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