pw_sync: Adds semaphores & mutexes
Adds the BinarySemaphore, CountingSemaphore, and Mutex to the
pw_sync module along with an STL backend for each.
Change-Id: I54a3a64e702202a319ed2c9068bf37412d3fd240
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/24241
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_sync/BUILD b/pw_sync/BUILD
index ceb60c6..18d1962 100644
--- a/pw_sync/BUILD
+++ b/pw_sync/BUILD
@@ -23,9 +23,105 @@
licenses(["notice"]) # Apache License 2.0
# TODO(pwbug/101): Need to add support for facades/backends to Bazel.
+PW_SYNC_BINARY_SEMAPHORE_BACKEND = "//pw_sync_stl:binary_semaphore"
+PW_SYNC_COUNTING_SEMAPHORE_BACKEND = "//pw_sync_stl:counting_semaphore"
+PW_SYNC_MUTEX_BACKEND = "//pw_sync_stl:mutex"
PW_SYNC_SPIN_LOCK_BACKEND = "//pw_sync_stl:spin_lock"
pw_cc_library(
+ name = "binary_semaphore_facade",
+ hdrs = [
+ "public/pw_sync/binary_semaphore.h",
+ ],
+ includes = ["public"],
+ srcs = [
+ "binary_semaphore.cc"
+ ],
+ deps = [
+ PW_SYNC_BINARY_SEMAPHORE_BACKEND + "_headers",
+ "//pw_chrono:system_clock",
+ "//pw_preprocessor",
+ ],
+)
+
+pw_cc_library(
+ name = "binary_semaphore",
+ deps = [
+ ":binary_semaphore_facade",
+ PW_SYNC_BINARY_SEMAPHORE_BACKEND + "_headers",
+ ],
+)
+
+pw_cc_library(
+ name = "binary_semaphore_backend",
+ deps = [
+ PW_SYNC_BINARY_SEMAPHORE_BACKEND,
+ ],
+)
+
+pw_cc_library(
+ name = "counting_semaphore_facade",
+ hdrs = [
+ "public/pw_sync/counting_semaphore.h",
+ ],
+ includes = ["public"],
+ srcs = [
+ "counting_semaphore.cc"
+ ],
+ deps = [
+ PW_SYNC_COUNTING_SEMAPHORE_BACKEND + "_headers",
+ "//pw_chrono:system_clock",
+ "//pw_preprocessor",
+ ],
+)
+
+pw_cc_library(
+ name = "counting_semaphore",
+ deps = [
+ ":counting_semaphore_facade",
+ PW_SYNC_COUNTING_SEMAPHORE_BACKEND + "_headers",
+ ],
+)
+
+pw_cc_library(
+ name = "counting_semaphore_backend",
+ deps = [
+ PW_SYNC_COUNTING_SEMAPHORE_BACKEND,
+ ],
+)
+
+pw_cc_library(
+ name = "mutex_facade",
+ hdrs = [
+ "public/pw_sync/mutex.h",
+ ],
+ includes = ["public"],
+ srcs = [
+ "mutex.cc"
+ ],
+ deps = [
+ PW_SYNC_MUTEX_BACKEND + "_headers",
+ "//pw_chrono:system_clock",
+ "//pw_preprocessor",
+ ],
+)
+
+pw_cc_library(
+ name = "mutex",
+ deps = [
+ ":mutex_facade",
+ PW_SYNC_MUTEX_BACKEND + "_headers",
+ ],
+)
+
+pw_cc_library(
+ name = "mutex_backend",
+ deps = [
+ PW_SYNC_MUTEX_BACKEND,
+ ],
+)
+
+pw_cc_library(
name = "spin_lock_facade",
hdrs = [
"public/pw_sync/spin_lock.h",
@@ -64,6 +160,45 @@
)
pw_cc_test(
+ name = "binary_semaphore_facade_test",
+ srcs = [
+ "binary_semaphore_facade_test.cc",
+ "binary_semaphore_facade_test_c.c",
+ ],
+ deps = [
+ ":binary_semaphore",
+ "//pw_preprocessor",
+ "//pw_unit_test",
+ ],
+)
+
+pw_cc_test(
+ name = "counting_semaphore_facade_test",
+ srcs = [
+ "counting_semaphore_facade_test.cc",
+ "counting_semaphore_facade_test_c.c",
+ ],
+ deps = [
+ ":counting_semaphore",
+ "//pw_preprocessor",
+ "//pw_unit_test",
+ ],
+)
+
+pw_cc_test(
+ name = "mutex_facade_test",
+ srcs = [
+ "mutex_facade_test.cc",
+ "mutex_facade_test_c.c",
+ ],
+ deps = [
+ ":mutex",
+ "//pw_preprocessor",
+ "//pw_unit_test",
+ ],
+)
+
+pw_cc_test(
name = "spin_lock_facade_test",
srcs = [
"spin_lock_facade_test.cc",