pw_multibuf: Replace Mutex with ISL

Per-region mutexes have size overhead that is much larger than
affordable for individual chunk regions. Prior to this change,
SimpleAllocator's LinkedRegionTracker was 144 bytes (!) when compiled
for host. After this change, it is 48 bytes (which is still too large,
but now the size can be reasonably improved by reducing the number of
pointer and size pairs).

Change-Id: Iae5b3e277d649b613f1b12be911464657e8890bf
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/200996
Pigweed-Auto-Submit: Taylor Cramer <cramertj@google.com>
Presubmit-Verified: CQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>
Commit-Queue: Auto-Submit <auto-submit@pigweed-service-accounts.iam.gserviceaccount.com>
Reviewed-by: Alexei Frolov <frolv@google.com>
diff --git a/pw_multibuf/BUILD.bazel b/pw_multibuf/BUILD.bazel
index e538e04..6ab06be 100644
--- a/pw_multibuf/BUILD.bazel
+++ b/pw_multibuf/BUILD.bazel
@@ -31,7 +31,7 @@
         "//pw_bytes",
         "//pw_preprocessor",
         "//pw_span",
-        "//pw_sync:mutex",
+        "//pw_sync:interrupt_spin_lock",
     ],
 )
 
diff --git a/pw_multibuf/BUILD.gn b/pw_multibuf/BUILD.gn
index c7fcd06..e1690ad 100644
--- a/pw_multibuf/BUILD.gn
+++ b/pw_multibuf/BUILD.gn
@@ -29,7 +29,7 @@
   public = [ "public/pw_multibuf/chunk.h" ]
   sources = [ "chunk.cc" ]
   public_deps = [
-    "$dir_pw_sync:mutex",
+    "$dir_pw_sync:interrupt_spin_lock",
     dir_pw_assert,
     dir_pw_bytes,
     dir_pw_preprocessor,
diff --git a/pw_multibuf/CMakeLists.txt b/pw_multibuf/CMakeLists.txt
index ec70f3f..dce0633 100644
--- a/pw_multibuf/CMakeLists.txt
+++ b/pw_multibuf/CMakeLists.txt
@@ -24,7 +24,7 @@
   pw_bytes
   pw_preprocessor
   pw_span
-  pw_sync.mutex
+  pw_sync.interrupt_spin_lock
   PRIVATE_DEPS
   pw_assert.check
   SOURCES
diff --git a/pw_multibuf/public/pw_multibuf/allocator.h b/pw_multibuf/public/pw_multibuf/allocator.h
index a946aaa..a2361d8 100644
--- a/pw_multibuf/public/pw_multibuf/allocator.h
+++ b/pw_multibuf/public/pw_multibuf/allocator.h
@@ -18,6 +18,7 @@
 #include "pw_async2/dispatcher.h"
 #include "pw_multibuf/multibuf.h"
 #include "pw_result/result.h"
+#include "pw_sync/interrupt_spin_lock.h"
 
 namespace pw::multibuf {
 
@@ -194,7 +195,7 @@
   void RemoveWaiterLocked(internal::AllocationWaiter*)
       PW_EXCLUSIVE_LOCKS_REQUIRED(lock_);
 
-  sync::Mutex lock_;
+  sync::InterruptSpinLock lock_;
   internal::AllocationWaiter* first_waiter_ PW_GUARDED_BY(lock_) = nullptr;
 };
 
diff --git a/pw_multibuf/public/pw_multibuf/chunk.h b/pw_multibuf/public/pw_multibuf/chunk.h
index 8c40e1d..35f77c5 100644
--- a/pw_multibuf/public/pw_multibuf/chunk.h
+++ b/pw_multibuf/public/pw_multibuf/chunk.h
@@ -17,7 +17,7 @@
 
 #include "pw_assert/assert.h"
 #include "pw_bytes/span.h"
-#include "pw_sync/mutex.h"
+#include "pw_sync/interrupt_spin_lock.h"
 
 namespace pw::multibuf {
 
@@ -309,7 +309,7 @@
   /// This allows chunks to:
   /// - know whether they can expand to fill neighboring regions of memory.
   /// - know when the last chunk has been destructed, triggering `Destroy`.
-  pw::sync::Mutex lock_;
+  pw::sync::InterruptSpinLock lock_;
   friend Chunk;
 };
 
diff --git a/pw_multibuf/public/pw_multibuf/simple_allocator.h b/pw_multibuf/public/pw_multibuf/simple_allocator.h
index 441bf83..df5640f 100644
--- a/pw_multibuf/public/pw_multibuf/simple_allocator.h
+++ b/pw_multibuf/public/pw_multibuf/simple_allocator.h
@@ -17,6 +17,7 @@
 #include "pw_containers/intrusive_list.h"
 #include "pw_multibuf/allocator.h"
 #include "pw_multibuf/multibuf.h"
+#include "pw_sync/interrupt_spin_lock.h"
 
 namespace pw::multibuf {
 
@@ -150,7 +151,7 @@
     }
   }
 
-  pw::sync::Mutex lock_;
+  pw::sync::InterruptSpinLock lock_;
   IntrusiveList<internal::LinkedRegionTracker> regions_ PW_GUARDED_BY(lock_);
   pw::allocator::Allocator& metadata_alloc_;
   const ByteSpan data_area_;