• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2021 The Pigweed Authors
2#
3# Licensed under the Apache License, Version 2.0 (the "License"); you may not
4# use this file except in compliance with the License. You may obtain a copy of
5# the License at
6#
7#     https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12# License for the specific language governing permissions and limitations under
13# the License.
14
15load("@rules_cc//cc:cc_library.bzl", "cc_library")
16load("@rules_python//sphinxdocs:sphinx_docs_library.bzl", "sphinx_docs_library")
17load(
18    "//pw_build:compatibility.bzl",
19    "host_backend_alias",
20    "incompatible_with_mcu",
21)
22load("//pw_build:pw_facade.bzl", "pw_facade")
23load("//pw_unit_test:pw_cc_test.bzl", "pw_cc_test")
24
25package(
26    default_visibility = ["//visibility:public"],
27    features = ["-layering_check"],
28)
29
30licenses(["notice"])
31
32pw_facade(
33    name = "binary_semaphore",
34    srcs = [
35        "binary_semaphore.cc",
36    ],
37    hdrs = [
38        "public/pw_sync/binary_semaphore.h",
39    ],
40    backend = ":binary_semaphore_backend",
41    strip_include_prefix = "public",
42    tags = ["noclangtidy"],
43    deps = [
44        "//pw_chrono:system_clock",
45        "//pw_preprocessor",
46    ],
47)
48
49label_flag(
50    name = "binary_semaphore_backend",
51    build_setting_default = ":binary_semaphore_unspecified_backend",
52)
53
54host_backend_alias(
55    name = "binary_semaphore_unspecified_backend",
56    backend = "//pw_sync_stl:binary_semaphore",
57)
58
59pw_facade(
60    name = "counting_semaphore",
61    srcs = [
62        "counting_semaphore.cc",
63    ],
64    hdrs = [
65        "public/pw_sync/counting_semaphore.h",
66    ],
67    backend = ":counting_semaphore_backend",
68    strip_include_prefix = "public",
69    tags = ["noclangtidy"],
70    deps = [
71        "//pw_chrono:system_clock",
72        "//pw_preprocessor",
73    ],
74)
75
76label_flag(
77    name = "counting_semaphore_backend",
78    build_setting_default = ":counting_semaphore_unspecified_backend",
79)
80
81host_backend_alias(
82    name = "counting_semaphore_unspecified_backend",
83    backend = "//pw_sync_stl:counting_semaphore",
84)
85
86cc_library(
87    name = "lock_annotations",
88    hdrs = [
89        "public/pw_sync/lock_annotations.h",
90    ],
91    strip_include_prefix = "public",
92    deps = [
93        "//pw_preprocessor",
94    ],
95)
96
97cc_library(
98    name = "lock_traits",
99    hdrs = [
100        "public/pw_sync/lock_traits.h",
101    ],
102    strip_include_prefix = "public",
103)
104
105cc_library(
106    name = "borrow",
107    hdrs = [
108        "public/pw_sync/borrow.h",
109    ],
110    strip_include_prefix = "public",
111    deps = [
112        ":lock_annotations",
113        ":lock_traits",
114        ":virtual_basic_lockable",
115        "//pw_assert:assert",
116    ],
117)
118
119cc_library(
120    name = "timed_borrow",
121    hdrs = [
122        "public/pw_sync/timed_borrow.h",
123    ],
124    strip_include_prefix = "public",
125    deps = [
126        ":borrow",
127        ":lock_annotations",
128        ":lock_traits",
129        ":virtual_basic_lockable",
130        "//pw_chrono:system_clock",
131    ],
132)
133
134cc_library(
135    name = "inline_borrowable",
136    hdrs = [
137        "public/pw_sync/inline_borrowable.h",
138        "public/pw_sync/internal/borrowable_storage.h",
139    ],
140    strip_include_prefix = "public",
141    deps = [
142        ":borrow",
143        ":mutex",
144        ":virtual_basic_lockable",
145    ],
146)
147
148cc_library(
149    name = "virtual_basic_lockable",
150    hdrs = [
151        "public/pw_sync/virtual_basic_lockable.h",
152    ],
153    strip_include_prefix = "public",
154    deps = [
155        ":lock_annotations",
156        "//pw_polyfill",
157    ],
158)
159
160pw_facade(
161    name = "mutex",
162    srcs = [
163        "mutex.cc",
164    ],
165    hdrs = [
166        "public/pw_sync/mutex.h",
167    ],
168    backend = ":mutex_backend",
169    strip_include_prefix = "public",
170    tags = ["noclangtidy"],
171    deps = [
172        ":lock_annotations",
173        ":virtual_basic_lockable",
174        "//pw_preprocessor",
175    ],
176)
177
178label_flag(
179    name = "mutex_backend",
180    build_setting_default = ":mutex_unspecified_backend",
181)
182
183host_backend_alias(
184    name = "mutex_unspecified_backend",
185    backend = "//pw_sync_stl:mutex",
186)
187
188pw_facade(
189    name = "timed_mutex",
190    srcs = [
191        "timed_mutex.cc",
192    ],
193    hdrs = [
194        "public/pw_sync/timed_mutex.h",
195    ],
196    backend = ":timed_mutex_backend",
197    strip_include_prefix = "public",
198    deps = [
199        ":lock_annotations",
200        ":mutex",
201        ":virtual_basic_lockable",
202        "//pw_chrono:system_clock",
203        "//pw_preprocessor",
204    ],
205)
206
207label_flag(
208    name = "timed_mutex_backend",
209    build_setting_default = ":timed_mutex_unspecified_backend",
210)
211
212host_backend_alias(
213    name = "timed_mutex_unspecified_backend",
214    backend = "//pw_sync_stl:timed_mutex",
215)
216
217pw_facade(
218    name = "recursive_mutex",
219    srcs = ["recursive_mutex.cc"],
220    hdrs = ["public/pw_sync/recursive_mutex.h"],
221    backend = ":recursive_mutex_backend",
222    strip_include_prefix = "public",
223    deps = [
224        ":lock_annotations",
225        "//pw_preprocessor",
226    ],
227)
228
229label_flag(
230    name = "recursive_mutex_backend",
231    build_setting_default = ":recursive_mutex_unspecified_backend",
232)
233
234host_backend_alias(
235    name = "recursive_mutex_unspecified_backend",
236    backend = "//pw_sync_stl:recursive_mutex",
237)
238
239pw_facade(
240    name = "interrupt_spin_lock",
241    srcs = [
242        "interrupt_spin_lock.cc",
243    ],
244    hdrs = [
245        "public/pw_sync/interrupt_spin_lock.h",
246    ],
247    backend = ":interrupt_spin_lock_backend",
248    strip_include_prefix = "public",
249    tags = ["noclangtidy"],
250    deps = [
251        ":lock_annotations",
252        ":virtual_basic_lockable",
253        "//pw_preprocessor",
254    ],
255)
256
257label_flag(
258    name = "interrupt_spin_lock_backend",
259    build_setting_default = ":interrupt_spin_lock_unspecified_backend",
260)
261
262host_backend_alias(
263    name = "interrupt_spin_lock_unspecified_backend",
264    backend = "//pw_sync_stl:interrupt_spin_lock",
265)
266
267pw_facade(
268    name = "thread_notification",
269    hdrs = [
270        "public/pw_sync/thread_notification.h",
271    ],
272    backend = ":thread_notification_backend",
273    strip_include_prefix = "public",
274    tags = ["noclangtidy"],
275    deps = [
276        "//pw_chrono:system_clock",
277    ],
278)
279
280label_flag(
281    name = "thread_notification_backend",
282    build_setting_default = ":thread_notification_unspecified_backend",
283)
284
285host_backend_alias(
286    name = "thread_notification_unspecified_backend",
287    backend = ":binary_semaphore_thread_notification_backend",
288)
289
290pw_facade(
291    name = "timed_thread_notification",
292    hdrs = [
293        "public/pw_sync/timed_thread_notification.h",
294    ],
295    backend = ":timed_thread_notification_backend",
296    strip_include_prefix = "public",
297    tags = ["noclangtidy"],
298    deps = [
299        ":thread_notification",
300        "//pw_chrono:system_clock",
301    ],
302)
303
304label_flag(
305    name = "timed_thread_notification_backend",
306    build_setting_default = ":timed_thread_notification_unspecified_backend",
307)
308
309host_backend_alias(
310    name = "timed_thread_notification_unspecified_backend",
311    backend = ":binary_semaphore_timed_thread_notification_backend",
312)
313
314cc_library(
315    name = "binary_semaphore_thread_notification_backend",
316    hdrs = [
317        "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h",
318        "public/pw_sync/backends/binary_semaphore_thread_notification_native.h",
319        "public_overrides/pw_sync_backend/thread_notification_inline.h",
320        "public_overrides/pw_sync_backend/thread_notification_native.h",
321    ],
322    includes = [
323        "public",
324        "public_overrides",
325    ],
326    tags = ["noclangtidy"],
327    target_compatible_with = incompatible_with_mcu(),
328    deps = [
329        ":binary_semaphore",
330        ":thread_notification.facade",
331    ],
332)
333
334cc_library(
335    name = "binary_semaphore_timed_thread_notification_backend",
336    hdrs = [
337        "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h",
338        "public_overrides/pw_sync_backend/timed_thread_notification_inline.h",
339    ],
340    includes = [
341        "public",
342        "public_overrides",
343    ],
344    tags = ["noclangtidy"],
345    target_compatible_with = incompatible_with_mcu(),
346    deps = [
347        ":binary_semaphore_thread_notification_backend",
348        ":timed_thread_notification.facade",
349        "//pw_chrono:system_clock",
350    ],
351)
352
353cc_library(
354    name = "yield_core",
355    hdrs = [
356        "public/pw_sync/yield_core.h",
357    ],
358    strip_include_prefix = "public",
359)
360
361cc_library(
362    name = "condition_variable_facade",
363    hdrs = [
364        "public/pw_sync/condition_variable.h",
365    ],
366    strip_include_prefix = "public",
367    tags = ["noclangtidy"],
368    deps = [
369        "//pw_chrono:system_clock",
370        "//pw_sync:mutex",
371    ],
372)
373
374# TODO: b/228998350 - This needs to be instantiated for each platform that
375# provides an implementation of $dir_pw_thread:test_threads and
376# $dir_pw_sync:condition_variable.
377# pw_cc_library(
378#     name = "condition_variable_test",
379#     srcs = ["condition_variable_test.cc"],
380#     deps = [
381#         ":condition_variable_facade",
382#         "//pw_containers:vector",
383#         "//pw_sync:mutex",
384#         "//pw_sync:timed_thread_notification",
385#         "//pw_thread:sleep",
386#         "//pw_thread:non_portable_test_thread_options",
387#         "//pw_thread:thread",
388#         "//pw_unit_test",
389#     ],
390# )
391#
392# Filegroup to mark `condition_variable_test.cc` as used for the linter:
393filegroup(
394    name = "condition_variable_test_filegroup",
395    srcs = ["condition_variable_test.cc"],
396)
397
398cc_library(
399    name = "lock_testing",
400    srcs = ["lock_testing.cc"],
401    hdrs = ["public/pw_sync/lock_testing.h"],
402    implementation_deps = ["//pw_assert:check"],
403    strip_include_prefix = "public",
404    deps = [
405        ":virtual_basic_lockable",
406        "//pw_chrono:system_clock",
407    ],
408)
409
410cc_library(
411    name = "borrow_testing",
412    hdrs = ["public/pw_sync/borrow_testing.h"],
413    strip_include_prefix = "public",
414    tags = ["noclangtidy"],
415    deps = [
416        ":borrow",
417        ":lock_traits",
418    ],
419)
420
421cc_library(
422    name = "timed_borrow_testing",
423    hdrs = ["public/pw_sync/timed_borrow_testing.h"],
424    strip_include_prefix = "public",
425    tags = ["noclangtidy"],
426    deps = [
427        ":borrow_testing",
428        ":timed_borrow",
429    ],
430)
431
432pw_cc_test(
433    name = "lock_traits_test",
434    srcs = ["lock_traits_test.cc"],
435    deps = [
436        ":lock_testing",
437        ":lock_traits",
438    ],
439)
440
441pw_cc_test(
442    name = "borrow_test",
443    srcs = ["borrow_test.cc"],
444    deps = [
445        ":borrow",
446        ":lock_testing",
447        ":timed_borrow_testing",
448    ],
449)
450
451pw_cc_test(
452    name = "inline_borrowable_test",
453    srcs = [
454        "inline_borrowable_test.cc",
455    ],
456    deps = [
457        ":inline_borrowable",
458        ":interrupt_spin_lock",
459        ":lock_annotations",
460        ":mutex",
461    ],
462)
463
464pw_cc_test(
465    name = "binary_semaphore_facade_test",
466    srcs = [
467        "binary_semaphore_facade_test.cc",
468        "binary_semaphore_facade_test_c.c",
469    ],
470    deps = [
471        ":binary_semaphore",
472        "//pw_preprocessor",
473    ],
474)
475
476pw_cc_test(
477    name = "counting_semaphore_facade_test",
478    srcs = [
479        "counting_semaphore_facade_test.cc",
480        "counting_semaphore_facade_test_c.c",
481    ],
482    deps = [
483        ":counting_semaphore",
484        "//pw_preprocessor",
485    ],
486)
487
488pw_cc_test(
489    name = "mutex_facade_test",
490    srcs = [
491        "mutex_facade_test.cc",
492        "mutex_facade_test_c.c",
493    ],
494    deps = [
495        ":borrow_testing",
496        ":mutex",
497        "//pw_preprocessor",
498    ],
499)
500
501pw_cc_test(
502    name = "timed_mutex_facade_test",
503    srcs = [
504        "timed_mutex_facade_test.cc",
505        "timed_mutex_facade_test_c.c",
506    ],
507    deps = [
508        ":timed_borrow_testing",
509        ":timed_mutex",
510        "//pw_chrono:system_clock",
511        "//pw_preprocessor",
512    ],
513)
514
515pw_cc_test(
516    name = "recursive_mutex_facade_test",
517    srcs = [
518        "recursive_mutex_facade_test.cc",
519        "recursive_mutex_facade_test_c.c",
520    ],
521    deps = [
522        ":recursive_mutex",
523        "//pw_preprocessor",
524    ],
525)
526
527pw_cc_test(
528    name = "interrupt_spin_lock_facade_test",
529    srcs = [
530        "interrupt_spin_lock_facade_test.cc",
531        "interrupt_spin_lock_facade_test_c.c",
532    ],
533    # TODO: https://pwbug.dev/325509758 - Doesn't work on the Pico yet; hangs
534    # indefinitely.
535    target_compatible_with = select({
536        "//pw_build/constraints/chipset:rp2040": ["@platforms//:incompatible"],
537        "//conditions:default": [],
538    }),
539    deps = [
540        ":borrow_testing",
541        ":interrupt_spin_lock",
542        "//pw_preprocessor",
543    ],
544)
545
546pw_cc_test(
547    name = "thread_notification_facade_test",
548    srcs = [
549        "thread_notification_facade_test.cc",
550    ],
551    deps = [":thread_notification"],
552)
553
554pw_cc_test(
555    name = "timed_thread_notification_facade_test",
556    srcs = [
557        "timed_thread_notification_facade_test.cc",
558    ],
559    deps = [
560        ":timed_thread_notification",
561        "//pw_chrono:system_clock",
562    ],
563)
564
565filegroup(
566    name = "doxygen",
567    srcs = [
568        "public/pw_sync/binary_semaphore.h",
569        "public/pw_sync/borrow.h",
570        "public/pw_sync/counting_semaphore.h",
571        "public/pw_sync/inline_borrowable.h",
572        "public/pw_sync/interrupt_spin_lock.h",
573        "public/pw_sync/lock_annotations.h",
574        "public/pw_sync/mutex.h",
575        "public/pw_sync/thread_notification.h",
576        "public/pw_sync/timed_borrow.h",
577        "public/pw_sync/timed_mutex.h",
578        "public/pw_sync/timed_thread_notification.h",
579        "public/pw_sync/virtual_basic_lockable.h",
580    ],
581)
582
583sphinx_docs_library(
584    name = "docs",
585    srcs = [
586        "backends.rst",
587        "docs.rst",
588    ],
589    prefix = "pw_sync/",
590    target_compatible_with = incompatible_with_mcu(),
591)
592