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( 16 "//pw_build:pigweed.bzl", 17 "pw_cc_test", 18 "pw_facade", 19) 20load( 21 "//pw_build:selects.bzl", 22 "TARGET_COMPATIBLE_WITH_HOST_SELECT", 23) 24 25package(default_visibility = ["//visibility:public"]) 26 27licenses(["notice"]) 28 29pw_facade( 30 name = "binary_semaphore", 31 srcs = [ 32 "binary_semaphore.cc", 33 ], 34 hdrs = [ 35 "public/pw_sync/binary_semaphore.h", 36 ], 37 backend = ":binary_semaphore_backend", 38 includes = ["public"], 39 deps = [ 40 "//pw_chrono:system_clock", 41 "//pw_preprocessor", 42 ], 43) 44 45label_flag( 46 name = "binary_semaphore_backend", 47 build_setting_default = ":binary_semaphore_backend_multiplexer", 48) 49 50cc_library( 51 name = "binary_semaphore_backend_multiplexer", 52 visibility = ["@pigweed//targets:__pkg__"], 53 deps = select({ 54 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:binary_semaphore"], 55 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:binary_semaphore"], 56 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:binary_semaphore"], 57 "//conditions:default": ["//pw_sync_stl:binary_semaphore"], 58 }), 59) 60 61pw_facade( 62 name = "counting_semaphore", 63 srcs = [ 64 "counting_semaphore.cc", 65 ], 66 hdrs = [ 67 "public/pw_sync/counting_semaphore.h", 68 ], 69 backend = ":counting_semaphore_backend", 70 includes = ["public"], 71 deps = [ 72 "//pw_chrono:system_clock", 73 "//pw_preprocessor", 74 ], 75) 76 77label_flag( 78 name = "counting_semaphore_backend", 79 build_setting_default = ":counting_semaphore_backend_multiplexer", 80) 81 82cc_library( 83 name = "counting_semaphore_backend_multiplexer", 84 visibility = ["@pigweed//targets:__pkg__"], 85 deps = select({ 86 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:counting_semaphore"], 87 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:counting_semaphore"], 88 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:counting_semaphore"], 89 "//conditions:default": ["//pw_sync_stl:counting_semaphore"], 90 }), 91) 92 93cc_library( 94 name = "lock_annotations", 95 hdrs = [ 96 "public/pw_sync/lock_annotations.h", 97 ], 98 includes = ["public"], 99 deps = [ 100 "//pw_preprocessor", 101 ], 102) 103 104cc_library( 105 name = "lock_traits", 106 hdrs = [ 107 "public/pw_sync/lock_traits.h", 108 ], 109 includes = ["public"], 110) 111 112cc_library( 113 name = "borrow", 114 hdrs = [ 115 "public/pw_sync/borrow.h", 116 ], 117 includes = ["public"], 118 deps = [ 119 ":lock_annotations", 120 ":lock_traits", 121 ":virtual_basic_lockable", 122 "//pw_assert", 123 ], 124) 125 126cc_library( 127 name = "inline_borrowable", 128 hdrs = [ 129 "public/pw_sync/inline_borrowable.h", 130 "public/pw_sync/internal/borrowable_storage.h", 131 ], 132 includes = ["public"], 133 deps = [ 134 ":borrow", 135 ":mutex", 136 ":virtual_basic_lockable", 137 ], 138) 139 140cc_library( 141 name = "virtual_basic_lockable", 142 hdrs = [ 143 "public/pw_sync/virtual_basic_lockable.h", 144 ], 145 includes = ["public"], 146 deps = [ 147 ":lock_annotations", 148 "//pw_polyfill", 149 ], 150) 151 152pw_facade( 153 name = "mutex", 154 srcs = [ 155 "mutex.cc", 156 ], 157 hdrs = [ 158 "public/pw_sync/mutex.h", 159 ], 160 backend = ":mutex_backend", 161 deps = [ 162 ":lock_annotations", 163 ":virtual_basic_lockable", 164 "//pw_preprocessor", 165 ], 166) 167 168label_flag( 169 name = "mutex_backend", 170 build_setting_default = ":mutex_backend_multiplexer", 171) 172 173cc_library( 174 name = "mutex_backend_multiplexer", 175 visibility = ["@pigweed//targets:__pkg__"], 176 deps = select({ 177 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:mutex"], 178 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:mutex"], 179 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:mutex"], 180 "//conditions:default": ["//pw_sync_stl:mutex"], 181 }), 182) 183 184pw_facade( 185 name = "timed_mutex", 186 srcs = [ 187 "timed_mutex.cc", 188 ], 189 hdrs = [ 190 "public/pw_sync/timed_mutex.h", 191 ], 192 backend = ":timed_mutex_backend", 193 deps = [ 194 ":lock_annotations", 195 ":mutex", 196 ":virtual_basic_lockable", 197 "//pw_chrono:system_clock", 198 "//pw_preprocessor", 199 ], 200) 201 202label_flag( 203 name = "timed_mutex_backend", 204 build_setting_default = ":timed_mutex_backend_multiplexer", 205) 206 207cc_library( 208 name = "timed_mutex_backend_multiplexer", 209 visibility = ["@pigweed//targets:__pkg__"], 210 deps = select({ 211 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:timed_mutex"], 212 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:timed_mutex"], 213 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:timed_mutex"], 214 "//conditions:default": ["//pw_sync_stl:timed_mutex"], 215 }), 216) 217 218cc_library( 219 name = "recursive_mutex_facade", 220 hdrs = ["public/pw_sync/recursive_mutex.h"], 221 includes = ["public"], 222 deps = [ 223 ":lock_annotations", 224 "//pw_preprocessor", 225 ], 226) 227 228cc_library( 229 name = "recursive_mutex", 230 srcs = ["recursive_mutex.cc"], 231 visibility = ["//pw_sync_baremetal:__pkg__"], 232 deps = [ 233 ":recursive_mutex_backend", 234 ":recursive_mutex_facade", 235 ], 236) 237 238label_flag( 239 name = "recursive_mutex_backend", 240 build_setting_default = ":recursive_mutex_backend_multiplexer", 241) 242 243cc_library( 244 name = "recursive_mutex_backend_multiplexer", 245 visibility = ["@pigweed//targets:__pkg__"], 246 deps = select({ 247 "@platforms//os:none": ["//pw_sync_baremetal:recursive_mutex"], 248 "//conditions:default": ["//pw_sync_stl:recursive_mutex"], 249 }), 250) 251 252pw_facade( 253 name = "interrupt_spin_lock", 254 srcs = [ 255 "interrupt_spin_lock.cc", 256 ], 257 hdrs = [ 258 "public/pw_sync/interrupt_spin_lock.h", 259 ], 260 backend = ":interrupt_spin_lock_backend", 261 deps = [ 262 ":lock_annotations", 263 ":virtual_basic_lockable", 264 "//pw_preprocessor", 265 ], 266) 267 268label_flag( 269 name = "interrupt_spin_lock_backend", 270 build_setting_default = ":interrupt_spin_lock_backend_multiplexer", 271) 272 273cc_library( 274 name = "interrupt_spin_lock_backend_multiplexer", 275 visibility = ["@pigweed//targets:__pkg__"], 276 deps = select({ 277 "//pw_build/constraints/rtos:embos": ["//pw_sync_embos:interrupt_spin_lock"], 278 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:interrupt_spin_lock"], 279 "//pw_build/constraints/rtos:threadx": ["//pw_sync_threadx:interrupt_spin_lock"], 280 "//conditions:default": ["//pw_sync_stl:interrupt_spin_lock"], 281 }), 282) 283 284pw_facade( 285 name = "thread_notification", 286 hdrs = [ 287 "public/pw_sync/thread_notification.h", 288 ], 289 backend = ":thread_notification_backend", 290 includes = ["public"], 291 deps = [ 292 "//pw_chrono:system_clock", 293 ], 294) 295 296label_flag( 297 name = "thread_notification_backend", 298 build_setting_default = ":thread_notification_backend_multiplexer", 299) 300 301cc_library( 302 name = "thread_notification_backend_multiplexer", 303 visibility = ["@pigweed//targets:__pkg__"], 304 deps = select({ 305 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:thread_notification"], 306 "//conditions:default": [":binary_semaphore_thread_notification_backend"], 307 }), 308) 309 310pw_facade( 311 name = "timed_thread_notification", 312 hdrs = [ 313 "public/pw_sync/timed_thread_notification.h", 314 ], 315 backend = ":timed_thread_notification_backend", 316 deps = [ 317 ":thread_notification", 318 "//pw_chrono:system_clock", 319 ], 320) 321 322label_flag( 323 name = "timed_thread_notification_backend", 324 build_setting_default = ":timed_thread_notification_backend_multiplexer", 325) 326 327cc_library( 328 name = "timed_thread_notification_backend_multiplexer", 329 visibility = ["@pigweed//targets:__pkg__"], 330 deps = select({ 331 "//pw_build/constraints/rtos:freertos": ["//pw_sync_freertos:timed_thread_notification"], 332 "//conditions:default": ["//pw_sync:binary_semaphore_timed_thread_notification_backend"], 333 }), 334) 335 336cc_library( 337 name = "binary_semaphore_thread_notification_backend", 338 hdrs = [ 339 "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h", 340 "public/pw_sync/backends/binary_semaphore_thread_notification_native.h", 341 "public_overrides/pw_sync_backend/thread_notification_inline.h", 342 "public_overrides/pw_sync_backend/thread_notification_native.h", 343 ], 344 includes = [ 345 "public", 346 "public_overrides", 347 ], 348 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 349 deps = [ 350 ":binary_semaphore", 351 ":thread_notification.facade", 352 ], 353) 354 355cc_library( 356 name = "binary_semaphore_timed_thread_notification_backend", 357 hdrs = [ 358 "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h", 359 "public_overrides/pw_sync_backend/timed_thread_notification_inline.h", 360 ], 361 includes = [ 362 "public", 363 "public_overrides", 364 ], 365 target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT), 366 deps = [ 367 ":binary_semaphore_thread_notification_backend", 368 "//pw_chrono:system_clock", 369 "//pw_sync:timed_thread_notification_facade", 370 ], 371) 372 373cc_library( 374 name = "yield_core", 375 hdrs = [ 376 "public/pw_sync/yield_core.h", 377 ], 378 includes = ["public"], 379) 380 381cc_library( 382 name = "condition_variable_facade", 383 hdrs = [ 384 "public/pw_sync/condition_variable.h", 385 ], 386 includes = ["public"], 387 deps = [ 388 "//pw_chrono:system_clock", 389 "//pw_sync:mutex", 390 ], 391) 392 393# TODO: b/228998350 - This needs to be instantiated for each platform that 394# provides an implementation of $dir_pw_thread:test_threads and 395# $dir_pw_sync:condition_variable. 396# pw_cc_library( 397# name = "condition_variable_test", 398# srcs = ["condition_variable_test.cc"], 399# deps = [ 400# ":condition_variable_facade", 401# "//pw_containers:vector", 402# "//pw_sync:mutex", 403# "//pw_sync:timed_thread_notification", 404# "//pw_thread:sleep", 405# "//pw_thread:non_portable_test_thread_options", 406# "//pw_thread:thread", 407# "//pw_unit_test", 408# ], 409# ) 410# 411# Filegroup to mark `condition_variable_test.cc` as used for the linter: 412filegroup( 413 name = "condition_variable_test_filegroup", 414 srcs = ["condition_variable_test.cc"], 415) 416 417cc_library( 418 name = "lock_testing", 419 srcs = ["lock_testing.cc"], 420 hdrs = ["public/pw_sync/lock_testing.h"], 421 includes = ["public"], 422 deps = [ 423 ":virtual_basic_lockable", 424 "//pw_assert", 425 ], 426) 427 428cc_library( 429 name = "borrow_lockable_tests", 430 hdrs = ["pw_sync_private/borrow_lockable_tests.h"], 431 deps = [ 432 ":borrow", 433 ":lock_traits", 434 ], 435) 436 437pw_cc_test( 438 name = "lock_traits_test", 439 srcs = ["lock_traits_test.cc"], 440 deps = [ 441 ":lock_testing", 442 ":lock_traits", 443 ], 444) 445 446pw_cc_test( 447 name = "borrow_test", 448 srcs = ["borrow_test.cc"], 449 deps = [ 450 ":borrow", 451 ":borrow_lockable_tests", 452 ":lock_testing", 453 "//pw_unit_test", 454 ], 455) 456 457pw_cc_test( 458 name = "inline_borrowable_test", 459 srcs = [ 460 "inline_borrowable_test.cc", 461 ], 462 deps = [ 463 ":inline_borrowable", 464 ":interrupt_spin_lock", 465 ":lock_annotations", 466 ":mutex", 467 "//pw_unit_test", 468 ], 469) 470 471pw_cc_test( 472 name = "binary_semaphore_facade_test", 473 srcs = [ 474 "binary_semaphore_facade_test.cc", 475 "binary_semaphore_facade_test_c.c", 476 ], 477 deps = [ 478 ":binary_semaphore", 479 "//pw_preprocessor", 480 "//pw_unit_test", 481 ], 482) 483 484pw_cc_test( 485 name = "counting_semaphore_facade_test", 486 srcs = [ 487 "counting_semaphore_facade_test.cc", 488 "counting_semaphore_facade_test_c.c", 489 ], 490 deps = [ 491 ":counting_semaphore", 492 "//pw_preprocessor", 493 "//pw_unit_test", 494 ], 495) 496 497pw_cc_test( 498 name = "mutex_facade_test", 499 srcs = [ 500 "mutex_facade_test.cc", 501 "mutex_facade_test_c.c", 502 ], 503 deps = [ 504 ":borrow_lockable_tests", 505 ":mutex", 506 "//pw_preprocessor", 507 "//pw_unit_test", 508 ], 509) 510 511pw_cc_test( 512 name = "timed_mutex_facade_test", 513 srcs = [ 514 "timed_mutex_facade_test.cc", 515 "timed_mutex_facade_test_c.c", 516 ], 517 deps = [ 518 ":borrow_lockable_tests", 519 ":timed_mutex", 520 "//pw_chrono:system_clock", 521 "//pw_preprocessor", 522 "//pw_unit_test", 523 ], 524) 525 526pw_cc_test( 527 name = "recursive_mutex_facade_test", 528 srcs = [ 529 "recursive_mutex_facade_test.cc", 530 "recursive_mutex_facade_test_c.c", 531 ], 532 deps = [ 533 ":recursive_mutex", 534 "//pw_preprocessor", 535 "//pw_unit_test", 536 ], 537) 538 539pw_cc_test( 540 name = "interrupt_spin_lock_facade_test", 541 srcs = [ 542 "interrupt_spin_lock_facade_test.cc", 543 "interrupt_spin_lock_facade_test_c.c", 544 ], 545 deps = [ 546 ":borrow_lockable_tests", 547 ":interrupt_spin_lock", 548 "//pw_preprocessor", 549 "//pw_unit_test", 550 ], 551) 552 553pw_cc_test( 554 name = "thread_notification_facade_test", 555 srcs = [ 556 "thread_notification_facade_test.cc", 557 ], 558 deps = [ 559 ":thread_notification", 560 "//pw_unit_test", 561 ], 562) 563 564pw_cc_test( 565 name = "timed_thread_notification_facade_test", 566 srcs = [ 567 "timed_thread_notification_facade_test.cc", 568 ], 569 deps = [ 570 ":timed_thread_notification", 571 "//pw_chrono:system_clock", 572 "//pw_unit_test", 573 ], 574) 575