pw_sync: add Borrowable helper for transactional guarding

Adds a templated pw::sync::Borrowable wrapper which permits
objects or pointers/references to them to be wrapped with a lock
to enable threadsafety wrapping for data and/or objects with
transactional APIs where an internal lock may not make sense.

Change-Id: Ic59df609e933a571fd755b943f8ffcaccc4a5201
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/59120
Reviewed-by: Wyatt Hepler <hepler@google.com>
Reviewed-by: Keir Mierle <keir@google.com>
Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed.google.com.iam.gserviceaccount.com>
diff --git a/pw_sync/BUILD.bazel b/pw_sync/BUILD.bazel
index 5687165..c8cbe1c 100644
--- a/pw_sync/BUILD.bazel
+++ b/pw_sync/BUILD.bazel
@@ -108,6 +108,17 @@
     ],
 )
 
+pw_cc_library(
+    name = "borrow",
+    hdrs = [
+        "public/pw_sync/borrow.h",
+    ],
+    includes = ["public"],
+    deps = [
+        "//pw_assert",
+    ],
+)
+
 pw_cc_facade(
     name = "mutex_facade",
     hdrs = [
@@ -333,6 +344,18 @@
 )
 
 pw_cc_test(
+    name = "borrow_test",
+    srcs = [
+        "borrow_test.cc",
+    ],
+    deps = [
+        ":borrow",
+        "//pw_assert",
+        "//pw_unit_test",
+    ],
+)
+
+pw_cc_test(
     name = "binary_semaphore_facade_test",
     srcs = [
         "binary_semaphore_facade_test.cc",