blob: 0b6da709f581b12e61b0bfe70369e134675943a9 [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 Bekkumafadef92021-10-20 11:56:06 -0700118 ":lock_annotations",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700119 ":virtual_basic_lockable",
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700120 "//pw_assert",
121 ],
122)
123
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700124pw_cc_library(
125 name = "virtual_basic_lockable",
126 hdrs = [
127 "public/pw_sync/virtual_basic_lockable.h",
128 ],
129 includes = ["public"],
130 deps = [
131 ":lock_annotations",
132 "//pw_polyfill",
133 ],
134)
135
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800136pw_cc_facade(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800137 name = "mutex_facade",
138 hdrs = [
139 "public/pw_sync/mutex.h",
140 ],
141 includes = ["public"],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800142 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800143 ":lock_annotations",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700144 ":virtual_basic_lockable",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800145 "//pw_preprocessor",
146 ],
147)
148
149pw_cc_library(
150 name = "mutex",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800151 srcs = [
152 "mutex.cc",
153 ],
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800154 deps = [
155 ":mutex_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800156 "@pigweed_config//:pw_sync_mutex_backend",
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800157 ],
158)
159
160pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800161 name = "mutex_backend_multiplexer",
162 visibility = ["@pigweed_config//:__pkg__"],
163 deps = select({
164 "@platforms//os:none": ["//pw_sync_baremetal:mutex"],
165 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:mutex"],
166 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:mutex"],
167 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:mutex"],
168 "//conditions:default": ["//pw_sync_stl:mutex"],
169 }),
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800170)
171
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800172pw_cc_facade(
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700173 name = "timed_mutex_facade",
174 hdrs = [
175 "public/pw_sync/timed_mutex.h",
176 ],
177 includes = ["public"],
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700178 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800179 ":lock_annotations",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700180 ":mutex_facade",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700181 ":virtual_basic_lockable",
Ewout van Bekkumcc9ef832021-04-08 08:51:16 -0700182 "//pw_chrono:system_clock",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700183 "//pw_preprocessor",
184 ],
185)
186
187pw_cc_library(
188 name = "timed_mutex",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800189 srcs = [
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800190 "timed_mutex.cc",
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800191 ],
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800192 deps = [
193 ":mutex",
194 ":timed_mutex_facade",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700195 ":virtual_basic_lockable",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800196 "@pigweed_config//:pw_sync_timed_mutex_backend",
197 ],
198)
199
200pw_cc_library(
201 name = "timed_mutex_backend_multiplexer",
202 visibility = ["@pigweed_config//:__pkg__"],
203 deps = select({
204 "@platforms//os:none": ["//pw_sync_baremetal:timed_mutex"],
205 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:timed_mutex"],
206 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:timed_mutex"],
207 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:timed_mutex"],
208 "//conditions:default": ["//pw_sync_stl:timed_mutex"],
209 }),
210)
211
212pw_cc_facade(
213 name = "interrupt_spin_lock_facade",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800214 hdrs = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800215 "public/pw_sync/interrupt_spin_lock.h",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800216 ],
217 includes = ["public"],
Ewout van Bekkum58901932020-11-09 12:46:52 -0800218 deps = [
Nathaniel Brougha1113be2021-03-07 09:05:41 +0800219 ":lock_annotations",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700220 ":virtual_basic_lockable",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800221 "//pw_preprocessor",
222 ],
223)
224
225pw_cc_library(
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800226 name = "interrupt_spin_lock",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800227 srcs = [
228 "interrupt_spin_lock.cc",
229 ],
Ewout van Bekkum58901932020-11-09 12:46:52 -0800230 deps = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800231 ":interrupt_spin_lock_facade",
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800232 "@pigweed_config//:pw_sync_interrupt_spin_lock_backend",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800233 ],
234)
235
236pw_cc_library(
Nathaniel Broughc2d57812021-04-18 22:52:00 +0800237 name = "interrupt_spin_lock_backend_multiplexer",
238 visibility = ["@pigweed_config//:__pkg__"],
239 deps = select({
240 "@platforms//os:none": ["//pw_sync_baremetal:interrupt_spin_lock"],
241 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:interrupt_spin_lock"],
242 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:interrupt_spin_lock"],
243 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:interrupt_spin_lock"],
244 "//conditions:default": ["//pw_sync_stl:interrupt_spin_lock"],
245 }),
Ewout van Bekkum58901932020-11-09 12:46:52 -0800246)
247
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700248pw_cc_facade(
249 name = "thread_notification_facade",
250 hdrs = [
251 "public/pw_sync/thread_notification.h",
252 ],
253 includes = ["public"],
254)
255
256pw_cc_library(
257 name = "thread_notification",
258 deps = [
259 ":thread_notification_facade",
260 "@pigweed_config//:pw_sync_thread_notification_backend",
261 ],
262)
263
264pw_cc_library(
265 name = "thread_notification_backend_multiplexer",
266 visibility = ["@pigweed_config//:__pkg__"],
267 deps = select({
268 "//conditions:default": ["//pw_sync:binary_semaphore_thread_notification_backend"],
269 }),
270)
271
272pw_cc_facade(
273 name = "timed_thread_notification_facade",
274 hdrs = [
275 "public/pw_sync/timed_thread_notification.h",
276 ],
277 includes = ["public"],
278 deps = [
279 ":thread_notification_facade",
280 "//pw_chrono:system_clock",
281 ],
282)
283
284pw_cc_library(
285 name = "timed_thread_notification",
286 deps = [
287 ":thread_notification",
288 ":timed_thread_notification_facade",
289 "@pigweed_config//:pw_sync_timed_thread_notification_backend",
290 ],
291)
292
293pw_cc_library(
294 name = "timed_thread_notification_backend_multiplexer",
295 visibility = ["@pigweed_config//:__pkg__"],
296 deps = select({
297 "//conditions:default": ["//pw_sync:binary_semaphore_timed_thread_notification_backend"],
298 }),
299)
300
301pw_cc_library(
302 name = "binary_semaphore_thread_notification_backend_headers",
303 hdrs = [
304 "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h",
305 "public/pw_sync/backends/binary_semaphore_thread_notification_native.h",
306 "public_overrides/pw_sync_backend/thread_notification_inline.h",
307 "public_overrides/pw_sync_backend/thread_notification_native.h",
308 ],
309 includes = [
310 "public",
311 "public_overrides",
312 ],
Rob Mohr9c266ab2021-06-14 17:48:49 -0700313 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
Ted Pudlik64110f52022-01-14 21:09:44 +0000314 deps = [":binary_semaphore"],
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700315)
316
317pw_cc_library(
318 name = "binary_semaphore_thread_notification_backend",
319 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
320 deps = [
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700321 ":binary_semaphore_facade",
Ted Pudlik64110f52022-01-14 21:09:44 +0000322 ":binary_semaphore_thread_notification_backend_headers",
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700323 ":thread_notification_facade",
324 ],
325)
326
327pw_cc_library(
328 name = "binary_semaphore_timed_thread_notification_backend_headers",
329 hdrs = [
330 "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h",
331 "public_overrides/pw_sync_backend/timed_thread_notification_inline.h",
332 ],
333 includes = [
334 "public",
335 "public_overrides",
336 ],
337 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
338 deps = [
339 ":binary_semaphore_thread_notification_backend_headers",
340 "//pw_chrono:system_clock",
341 ],
342)
343
344pw_cc_library(
345 name = "binary_semaphore_timed_thread_notification_backend",
346 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
347 deps = [
348 ":binary_semaphore_thread_notification_backend",
349 ":binary_semaphore_timed_thread_notification_backend_headers",
350 "//pw_sync:timed_thread_notification_facade",
351 ],
352)
353
Ewout van Bekkum58901932020-11-09 12:46:52 -0800354pw_cc_library(
355 name = "yield_core",
356 hdrs = [
357 "public/pw_sync/yield_core.h",
358 ],
359 includes = ["public"],
360)
361
362pw_cc_test(
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700363 name = "borrow_test",
364 srcs = [
365 "borrow_test.cc",
366 ],
367 deps = [
368 ":borrow",
Ewout van Bekkumbaf2fdc2021-09-09 14:11:51 -0700369 ":virtual_basic_lockable",
Ewout van Bekkumf6c3a782021-08-31 11:23:35 -0700370 "//pw_assert",
371 "//pw_unit_test",
372 ],
373)
374
375pw_cc_test(
Ewout van Bekkum9618d8a2020-11-09 12:46:52 -0800376 name = "binary_semaphore_facade_test",
377 srcs = [
378 "binary_semaphore_facade_test.cc",
379 "binary_semaphore_facade_test_c.c",
380 ],
381 deps = [
382 ":binary_semaphore",
383 "//pw_preprocessor",
384 "//pw_unit_test",
385 ],
386)
387
388pw_cc_test(
389 name = "counting_semaphore_facade_test",
390 srcs = [
391 "counting_semaphore_facade_test.cc",
392 "counting_semaphore_facade_test_c.c",
393 ],
394 deps = [
395 ":counting_semaphore",
396 "//pw_preprocessor",
397 "//pw_unit_test",
398 ],
399)
400
401pw_cc_test(
402 name = "mutex_facade_test",
403 srcs = [
404 "mutex_facade_test.cc",
405 "mutex_facade_test_c.c",
406 ],
407 deps = [
408 ":mutex",
409 "//pw_preprocessor",
410 "//pw_unit_test",
411 ],
412)
413
414pw_cc_test(
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700415 name = "timed_mutex_facade_test",
416 srcs = [
417 "timed_mutex_facade_test.cc",
418 "timed_mutex_facade_test_c.c",
419 ],
420 deps = [
421 ":timed_mutex",
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700422 "//pw_chrono:system_clock",
Ewout van Bekkum6f5b8fb2021-04-06 16:15:22 -0700423 "//pw_preprocessor",
424 "//pw_unit_test",
425 ],
426)
427
428pw_cc_test(
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800429 name = "interrupt_spin_lock_facade_test",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800430 srcs = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800431 "interrupt_spin_lock_facade_test.cc",
432 "interrupt_spin_lock_facade_test_c.c",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800433 ],
434 deps = [
Ewout van Bekkum126e0112021-03-12 10:59:49 -0800435 ":interrupt_spin_lock",
Ewout van Bekkum58901932020-11-09 12:46:52 -0800436 "//pw_preprocessor",
437 "//pw_unit_test",
438 ],
439)
Ewout van Bekkumf0106062021-05-06 14:08:33 -0700440
441pw_cc_test(
442 name = "thread_notification_facade_test",
443 srcs = [
444 "thread_notification_facade_test.cc",
445 "thread_notification_facade_test_c.c",
446 ],
447 deps = [
448 ":thread_notification",
449 "//pw_unit_test",
450 ],
451)
452
453pw_cc_test(
454 name = "timed_thread_notification_facade_test",
455 srcs = [
456 "timed_thread_notification_facade_test.cc",
457 "timed_thread_notification_facade_test_c.c",
458 ],
459 deps = [
460 ":timed_thread_notification",
461 "//pw_chrono:system_clock",
462 "//pw_unit_test",
463 ],
464)