pw_sync: add ThreadNotification and TimedThreadNotification

Adds the ThreadNotification and TimedThreadNotification facades
to pw_sync.

Also provides a generic and not-optimized backend based on
pw::sync::BinarySemaphore which is immediately used for the host
target.

Change-Id: Iac067ae10f32f9633907c05365338eb575d35097
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/44020
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_sync/BUILD b/pw_sync/BUILD
index 6b63e1f..9b9f683 100644
--- a/pw_sync/BUILD
+++ b/pw_sync/BUILD
@@ -1,4 +1,4 @@
-# Copyright 2020 The Pigweed Authors
+# Copyright 2021 The Pigweed Authors
 #
 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
 # use this file except in compliance with the License. You may obtain a copy of
@@ -18,6 +18,10 @@
     "pw_cc_library",
     "pw_cc_test",
 )
+load(
+    "//pw_build:selects.bzl",
+    "TARGET_COMPATIBLE_WITH_HOST_SELECT",
+)
 
 package(default_visibility = ["//visibility:public"])
 
@@ -212,6 +216,114 @@
     }),
 )
 
+pw_cc_facade(
+    name = "thread_notification_facade",
+    hdrs = [
+        "public/pw_sync/thread_notification.h",
+    ],
+    includes = ["public"],
+)
+
+pw_cc_library(
+    name = "thread_notification",
+    deps = [
+        ":thread_notification_facade",
+        "@pigweed_config//:pw_sync_thread_notification_backend",
+    ],
+)
+
+pw_cc_library(
+    name = "thread_notification_backend_multiplexer",
+    visibility = ["@pigweed_config//:__pkg__"],
+    deps = select({
+        "//conditions:default": ["//pw_sync:binary_semaphore_thread_notification_backend"],
+    }),
+)
+
+pw_cc_facade(
+    name = "timed_thread_notification_facade",
+    hdrs = [
+        "public/pw_sync/timed_thread_notification.h",
+    ],
+    includes = ["public"],
+    deps = [
+        ":thread_notification_facade",
+        "//pw_chrono:system_clock",
+    ],
+)
+
+pw_cc_library(
+    name = "timed_thread_notification",
+    deps = [
+        ":thread_notification",
+        ":timed_thread_notification_facade",
+        "@pigweed_config//:pw_sync_timed_thread_notification_backend",
+    ],
+)
+
+pw_cc_library(
+    name = "timed_thread_notification_backend_multiplexer",
+    visibility = ["@pigweed_config//:__pkg__"],
+    deps = select({
+        "//conditions:default": ["//pw_sync:binary_semaphore_timed_thread_notification_backend"],
+    }),
+)
+
+pw_cc_library(
+    name = "binary_semaphore_thread_notification_backend_headers",
+    hdrs = [
+        "public/pw_sync/backends/binary_semaphore_thread_notification_inline.h",
+        "public/pw_sync/backends/binary_semaphore_thread_notification_native.h",
+        "public_overrides/pw_sync_backend/thread_notification_inline.h",
+        "public_overrides/pw_sync_backend/thread_notification_native.h",
+    ],
+    includes = [
+        "public",
+        "public_overrides",
+    ],
+    deps = [
+        ":binary_semaphore_headers",
+    ],
+    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
+)
+
+pw_cc_library(
+    name = "binary_semaphore_thread_notification_backend",
+    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
+    deps = [
+        ":binary_semaphore_thread_notification_headers",
+        ":binary_semaphore_facade",
+        ":thread_notification_facade",
+    ],
+)
+
+pw_cc_library(
+    name = "binary_semaphore_timed_thread_notification_backend_headers",
+    hdrs = [
+        "public/pw_sync/backends/binary_semaphore_timed_thread_notification_inline.h",
+        "public_overrides/pw_sync_backend/timed_thread_notification_inline.h",
+    ],
+    includes = [
+        "public",
+        "public_overrides",
+    ],
+    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
+    deps = [
+        ":binary_semaphore_thread_notification_backend_headers",
+        "//pw_chrono:system_clock",
+    ],
+)
+
+pw_cc_library(
+    name = "binary_semaphore_timed_thread_notification_backend",
+    target_compatible_with = select(TARGET_COMPATIBLE_WITH_HOST_SELECT),
+    deps = [
+        ":binary_semaphore_thread_notification_backend",
+        ":binary_semaphore_timed_thread_notification_backend_headers",
+        "//pw_sync:timed_thread_notification_facade",
+    ],
+)
+
 pw_cc_library(
     name = "yield_core",
     hdrs = [
@@ -267,6 +379,7 @@
     ],
     deps = [
         ":timed_mutex",
+        "//pw_chrono:system_clock",
         "//pw_preprocessor",
         "//pw_unit_test",
     ],
@@ -284,3 +397,28 @@
         "//pw_unit_test",
     ],
 )
+
+pw_cc_test(
+    name = "thread_notification_facade_test",
+    srcs = [
+        "thread_notification_facade_test.cc",
+        "thread_notification_facade_test_c.c",
+    ],
+    deps = [
+        ":thread_notification",
+        "//pw_unit_test",
+    ],
+)
+
+pw_cc_test(
+    name = "timed_thread_notification_facade_test",
+    srcs = [
+        "timed_thread_notification_facade_test.cc",
+        "timed_thread_notification_facade_test_c.c",
+    ],
+    deps = [
+        ":timed_thread_notification",
+        "//pw_chrono:system_clock",
+        "//pw_unit_test",
+    ],
+)