blob: d3958633e8ae14f169ade05651926035d0cb389b [file] [log] [blame]
Ewout van Bekkumf0106062021-05-06 14:08:33 -07001# Copyright 2021 The Pigweed Authors
Ewout van Bekkum58901932020-11-09 12:46:52 -08002#
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(
16 "//pw_build:pigweed.bzl",
Nathaniel Broughc2d57812021-04-18 22:52:00 +080017 "pw_cc_facade",
Ewout van Bekkum58901932020-11-09 12:46:52 -080018 "pw_cc_library",
19 "pw_cc_test",
20)
Ewout van Bekkumf0106062021-05-06 14:08:33 -070021load(
22 "//pw_build:selects.bzl",
23 "TARGET_COMPATIBLE_WITH_HOST_SELECT",
24)
Ewout van Bekkum58901932020-11-09 12:46:52 -080025
26package(default_visibility = ["//visibility:public"])
27
Rob Mohr5fc25412021-06-23 09:35:23 -070028licenses(["notice"])
Ewout van Bekkum58901932020-11-09 12:46:52 -080029
Nathaniel Broughc2d57812021-04-18 22:52:00 +080030pw_cc_facade(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080031 name = "binary_semaphore_facade",
32 hdrs = [
33 "public/pw_sync/binary_semaphore.h",
34 ],
35 includes = ["public"],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080036 deps = [
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080037 "//pw_chrono:system_clock",
38 "//pw_preprocessor",
39 ],
40)
41
42pw_cc_library(
43 name = "binary_semaphore",
Nathaniel Broughc2d57812021-04-18 22:52:00 +080044 srcs = [
45 "binary_semaphore.cc",
46 ],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080047 deps = [
48 ":binary_semaphore_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +080049 "@pigweed_config//:pw_sync_binary_semaphore_backend",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080050 ],
51)
52
53pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +080054 name = "binary_semaphore_backend_multiplexer",
55 visibility = ["@pigweed_config//:__pkg__"],
56 deps = select({
57 "@platforms//os:none": ["//pw_sync_baremetal:binary_semaphore"],
58 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:binary_semaphore"],
59 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:binary_semaphore"],
60 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:binary_semaphore"],
61 "//conditions:default": ["//pw_sync_stl:binary_semaphore"],
62 }),
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080063)
64
Nathaniel Broughc2d57812021-04-18 22:52:00 +080065pw_cc_facade(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080066 name = "counting_semaphore_facade",
67 hdrs = [
68 "public/pw_sync/counting_semaphore.h",
69 ],
70 includes = ["public"],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080071 deps = [
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080072 "//pw_chrono:system_clock",
73 "//pw_preprocessor",
74 ],
75)
76
77pw_cc_library(
78 name = "counting_semaphore",
Nathaniel Broughc2d57812021-04-18 22:52:00 +080079 srcs = [
80 "counting_semaphore.cc",
81 ],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080082 deps = [
83 ":counting_semaphore_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +080084 "@pigweed_config//:pw_sync_counting_semaphore_backend",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080085 ],
86)
87
88pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +080089 name = "counting_semaphore_backend_multiplexer",
90 visibility = ["@pigweed_config//:__pkg__"],
91 deps = select({
92 "@platforms//os:none": ["//pw_sync_baremetal:counting_semaphore"],
93 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:counting_semaphore"],
94 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:counting_semaphore"],
95 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:counting_semaphore"],
96 "//conditions:default": ["//pw_sync_stl:counting_semaphore"],
97 }),
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -080098)
99
100pw_cc_library(
Ewout van Bekkumcc9ef832021-04-08 08:51:16 -0700101 name = "lock_annotations",
102 hdrs = [
103 "public/pw_sync/lock_annotations.h",
104 ],
105 includes = ["public"],
106 deps = [
107 "//pw_preprocessor",
108 ],
109)
110
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700111pw_cc_library(
112 name = "borrow",
113 hdrs = [
114 "public/pw_sync/borrow.h",
115 ],
116 includes = ["public"],
117 deps = [
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700118 ":virtual_basic_lockable",
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700119 "//pw_assert",
120 ],
121)
122
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700123pw_cc_library(
124 name = "virtual_basic_lockable",
125 hdrs = [
126 "public/pw_sync/virtual_basic_lockable.h",
127 ],
128 includes = ["public"],
129 deps = [
130 ":lock_annotations",
131 "//pw_polyfill",
132 ],
133)
134
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800135pw_cc_facade(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800136 name = "mutex_facade",
137 hdrs = [
138 "public/pw_sync/mutex.h",
139 ],
140 includes = ["public"],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800141 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800142 ":lock_annotations",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700143 ":virtual_basic_lockable",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800144 "//pw_preprocessor",
145 ],
146)
147
148pw_cc_library(
149 name = "mutex",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800150 srcs = [
151 "mutex.cc",
152 ],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800153 deps = [
154 ":mutex_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800155 "@pigweed_config//:pw_sync_mutex_backend",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800156 ],
157)
158
159pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800160 name = "mutex_backend_multiplexer",
161 visibility = ["@pigweed_config//:__pkg__"],
162 deps = select({
163 "@platforms//os:none": ["//pw_sync_baremetal:mutex"],
164 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:mutex"],
165 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:mutex"],
166 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:mutex"],
167 "//conditions:default": ["//pw_sync_stl:mutex"],
168 }),
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800169)
170
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800171pw_cc_facade(
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700172 name = "timed_mutex_facade",
173 hdrs = [
174 "public/pw_sync/timed_mutex.h",
175 ],
176 includes = ["public"],
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700177 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800178 ":lock_annotations",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700179 ":mutex_facade",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700180 ":virtual_basic_lockable",
Ewout van Bekkumcc9ef832021-04-08 08:51:16 -0700181 "//pw_chrono:system_clock",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700182 "//pw_preprocessor",
183 ],
184)
185
186pw_cc_library(
187 name = "timed_mutex",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800188 srcs = [
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800189 "timed_mutex.cc",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800190 ],
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800191 deps = [
192 ":mutex",
193 ":timed_mutex_facade",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700194 ":virtual_basic_lockable",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800195 "@pigweed_config//:pw_sync_timed_mutex_backend",
196 ],
197)
198
199pw_cc_library(
200 name = "timed_mutex_backend_multiplexer",
201 visibility = ["@pigweed_config//:__pkg__"],
202 deps = select({
203 "@platforms//os:none": ["//pw_sync_baremetal:timed_mutex"],
204 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:timed_mutex"],
205 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:timed_mutex"],
206 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:timed_mutex"],
207 "//conditions:default": ["//pw_sync_stl:timed_mutex"],
208 }),
209)
210
211pw_cc_facade(
212 name = "interrupt_spin_lock_facade",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800213 hdrs = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800214 "public/pw_sync/interrupt_spin_lock.h",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800215 ],
216 includes = ["public"],
Ewout van Bekkum58901932020-11-09 12:46:52 -0800217 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800218 ":lock_annotations",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700219 ":virtual_basic_lockable",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800220 "//pw_preprocessor",
221 ],
222)
223
224pw_cc_library(
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800225 name = "interrupt_spin_lock",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800226 srcs = [
227 "interrupt_spin_lock.cc",
228 ],
Ewout van Bekkum58901932020-11-09 12:46:52 -0800229 deps = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800230 ":interrupt_spin_lock_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800231 "@pigweed_config//:pw_sync_interrupt_spin_lock_backend",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800232 ],
233)
234
235pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800236 name = "interrupt_spin_lock_backend_multiplexer",
237 visibility = ["@pigweed_config//:__pkg__"],
238 deps = select({
239 "@platforms//os:none": ["//pw_sync_baremetal:interrupt_spin_lock"],
240 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:interrupt_spin_lock"],
241 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:interrupt_spin_lock"],
242 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:interrupt_spin_lock"],
243 "//conditions:default": ["//pw_sync_stl:interrupt_spin_lock"],
244 }),
Ewout van Bekkum58901932020-11-09 12:46:52 -0800245)
246
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700247pw_cc_facade(
248 name = "thread_notification_facade",
249 hdrs = [
250 "public/pw_sync/thread_notification.h",
251 ],
252 includes = ["public"],
253)
254
255pw_cc_library(
256 name = "thread_notification",
257 deps = [
258 ":thread_notification_facade",
259 "@pigweed_config//:pw_sync_thread_notification_backend",
260 ],
261)
262
263pw_cc_library(
264 name = "thread_notification_backend_multiplexer",
265 visibility = ["@pigweed_config//:__pkg__"],
266 deps = select({
267 "//conditions:default": ["//pw_sync:binary_semaphore_thread_notification_backend"],
268 }),
269)
270
271pw_cc_facade(
272 name = "timed_thread_notification_facade",
273 hdrs = [
274 "public/pw_sync/timed_thread_notification.h",
275 ],
276 includes = ["public"],
277 deps = [
278 ":thread_notification_facade",
279 "//pw_chrono:system_clock",
280 ],
281)
282
283pw_cc_library(
284 name = "timed_thread_notification",
285 deps = [
286 ":thread_notification",
287 ":timed_thread_notification_facade",
288 "@pigweed_config//:pw_sync_timed_thread_notification_backend",
289 ],
290)
291
292pw_cc_library(
293 name = "timed_thread_notification_backend_multiplexer",
294 visibility = ["@pigweed_config//:__pkg__"],
295 deps = select({
296 "//conditions:default": ["//pw_sync:binary_semaphore_timed_thread_notification_backend"],
297 }),
298)
299
300pw_cc_library(
301 name = "binary_semaphore_thread_notification_backend_headers",
302 hdrs = [
303 "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h",
304 "public/pw_sync/backends/binary_semaphore_thread_notification_native.h",
305 "public_overrides/pw_sync_backend/thread_notification_inline.h",
306 "public_overrides/pw_sync_backend/thread_notification_native.h",
307 ],
308 includes = [
309 "public",
310 "public_overrides",
311 ],
Rob Mohr9c266ab2021-06-14 17:48:49 -0700312 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700313 deps = [
314 ":binary_semaphore_headers",
315 ],
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700316)
317
318pw_cc_library(
319 name = "binary_semaphore_thread_notification_backend",
320 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
321 deps = [
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700322 ":binary_semaphore_facade",
Rob Mohr9c266ab2021-06-14 17:48:49 -0700323 ":binary_semaphore_thread_notification_headers",
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700324 ":thread_notification_facade",
325 ],
326)
327
328pw_cc_library(
329 name = "binary_semaphore_timed_thread_notification_backend_headers",
330 hdrs = [
331 "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h",
332 "public_overrides/pw_sync_backend/timed_thread_notification_inline.h",
333 ],
334 includes = [
335 "public",
336 "public_overrides",
337 ],
338 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
339 deps = [
340 ":binary_semaphore_thread_notification_backend_headers",
341 "//pw_chrono:system_clock",
342 ],
343)
344
345pw_cc_library(
346 name = "binary_semaphore_timed_thread_notification_backend",
347 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
348 deps = [
349 ":binary_semaphore_thread_notification_backend",
350 ":binary_semaphore_timed_thread_notification_backend_headers",
351 "//pw_sync:timed_thread_notification_facade",
352 ],
353)
354
Ewout van Bekkum58901932020-11-09 12:46:52 -0800355pw_cc_library(
356 name = "yield_core",
357 hdrs = [
358 "public/pw_sync/yield_core.h",
359 ],
360 includes = ["public"],
361)
362
363pw_cc_test(
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700364 name = "borrow_test",
365 srcs = [
366 "borrow_test.cc",
367 ],
368 deps = [
369 ":borrow",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700370 ":virtual_basic_lockable",
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700371 "//pw_assert",
372 "//pw_unit_test",
373 ],
374)
375
376pw_cc_test(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800377 name = "binary_semaphore_facade_test",
378 srcs = [
379 "binary_semaphore_facade_test.cc",
380 "binary_semaphore_facade_test_c.c",
381 ],
382 deps = [
383 ":binary_semaphore",
384 "//pw_preprocessor",
385 "//pw_unit_test",
386 ],
387)
388
389pw_cc_test(
390 name = "counting_semaphore_facade_test",
391 srcs = [
392 "counting_semaphore_facade_test.cc",
393 "counting_semaphore_facade_test_c.c",
394 ],
395 deps = [
396 ":counting_semaphore",
397 "//pw_preprocessor",
398 "//pw_unit_test",
399 ],
400)
401
402pw_cc_test(
403 name = "mutex_facade_test",
404 srcs = [
405 "mutex_facade_test.cc",
406 "mutex_facade_test_c.c",
407 ],
408 deps = [
409 ":mutex",
410 "//pw_preprocessor",
411 "//pw_unit_test",
412 ],
413)
414
415pw_cc_test(
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700416 name = "timed_mutex_facade_test",
417 srcs = [
418 "timed_mutex_facade_test.cc",
419 "timed_mutex_facade_test_c.c",
420 ],
421 deps = [
422 ":timed_mutex",
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700423 "//pw_chrono:system_clock",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700424 "//pw_preprocessor",
425 "//pw_unit_test",
426 ],
427)
428
429pw_cc_test(
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800430 name = "interrupt_spin_lock_facade_test",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800431 srcs = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800432 "interrupt_spin_lock_facade_test.cc",
433 "interrupt_spin_lock_facade_test_c.c",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800434 ],
435 deps = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800436 ":interrupt_spin_lock",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800437 "//pw_preprocessor",
438 "//pw_unit_test",
439 ],
440)
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700441
442pw_cc_test(
443 name = "thread_notification_facade_test",
444 srcs = [
445 "thread_notification_facade_test.cc",
446 "thread_notification_facade_test_c.c",
447 ],
448 deps = [
449 ":thread_notification",
450 "//pw_unit_test",
451 ],
452)
453
454pw_cc_test(
455 name = "timed_thread_notification_facade_test",
456 srcs = [
457 "timed_thread_notification_facade_test.cc",
458 "timed_thread_notification_facade_test_c.c",
459 ],
460 deps = [
461 ":timed_thread_notification",
462 "//pw_chrono:system_clock",
463 "//pw_unit_test",
464 ],
465)