pw_sync: change SpinLock to have a constexpr ctor

Changes the pw::sync::SpinLock facade to have a constexpr
constructor. Outside of making the constructor possible to be
evaluated at compile time, this grossly simplifies the use of the
SpinLock during early boot before static global C++ constructors
are executed.

Change-Id: Iebe6708f27e5e235c981e5d9d6431f2d9f732b52
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/36580
Reviewed-by: Ewout van Bekkum <ewout@google.com>
Reviewed-by: Wyatt Hepler <hepler@google.com>
Commit-Queue: Ewout van Bekkum <ewout@google.com>
diff --git a/pw_sync/public/pw_sync/spin_lock.h b/pw_sync/public/pw_sync/spin_lock.h
index fdce5e3..a59879b 100644
--- a/pw_sync/public/pw_sync/spin_lock.h
+++ b/pw_sync/public/pw_sync/spin_lock.h
@@ -48,7 +48,7 @@
  public:
   using native_handle_type = backend::NativeSpinLockHandle;
 
-  SpinLock();
+  constexpr SpinLock();
   ~SpinLock() = default;
   SpinLock(const SpinLock&) = delete;
   SpinLock(SpinLock&&) = delete;
diff --git a/pw_sync_baremetal/public/pw_sync_baremetal/spin_lock_inline.h b/pw_sync_baremetal/public/pw_sync_baremetal/spin_lock_inline.h
index 801d738..3ed9562 100644
--- a/pw_sync_baremetal/public/pw_sync_baremetal/spin_lock_inline.h
+++ b/pw_sync_baremetal/public/pw_sync_baremetal/spin_lock_inline.h
@@ -19,7 +19,7 @@
 
 namespace pw::sync {
 
-inline SpinLock::SpinLock() : native_type_() {}
+constexpr SpinLock::SpinLock() : native_type_() {}
 
 inline void SpinLock::lock() { PW_ASSERT(try_lock()); }
 
diff --git a/pw_sync_embos/public/pw_sync_embos/spin_lock_inline.h b/pw_sync_embos/public/pw_sync_embos/spin_lock_inline.h
index 7fb6f62..697de73 100644
--- a/pw_sync_embos/public/pw_sync_embos/spin_lock_inline.h
+++ b/pw_sync_embos/public/pw_sync_embos/spin_lock_inline.h
@@ -17,10 +17,7 @@
 
 namespace pw::sync {
 
-// TODO(ewout): update the SpinLock facade to be constexpr constructable which
-// should help use of spin locks before C++ construction massively and appears
-// to be portable.
-inline SpinLock::SpinLock() : native_type_{.locked{false}} {}
+constexpr SpinLock::SpinLock() : native_type_{.locked{false}} {}
 
 inline SpinLock::native_handle_type SpinLock::native_handle() {
   return native_type_;
diff --git a/pw_sync_freertos/public/pw_sync_freertos/spin_lock_inline.h b/pw_sync_freertos/public/pw_sync_freertos/spin_lock_inline.h
index af81d78..ae08b0d 100644
--- a/pw_sync_freertos/public/pw_sync_freertos/spin_lock_inline.h
+++ b/pw_sync_freertos/public/pw_sync_freertos/spin_lock_inline.h
@@ -17,8 +17,8 @@
 
 namespace pw::sync {
 
-inline SpinLock::SpinLock()
-    : native_type_{.locked = false, .saved_interrupt_mask = 0} {}
+constexpr SpinLock::SpinLock()
+    : native_type_{.locked{false}, .saved_interrupt_mask = 0} {}
 
 inline SpinLock::native_handle_type SpinLock::native_handle() {
   return native_type_;
diff --git a/pw_sync_stl/public/pw_sync_stl/spin_lock_inline.h b/pw_sync_stl/public/pw_sync_stl/spin_lock_inline.h
index 57572d0..a50c231 100644
--- a/pw_sync_stl/public/pw_sync_stl/spin_lock_inline.h
+++ b/pw_sync_stl/public/pw_sync_stl/spin_lock_inline.h
@@ -18,7 +18,7 @@
 
 namespace pw::sync {
 
-inline SpinLock::SpinLock() : native_type_() {}
+constexpr SpinLock::SpinLock() : native_type_() {}
 
 inline void SpinLock::lock() {
   while (!try_lock()) {
diff --git a/pw_sync_threadx/public/pw_sync_threadx/spin_lock_inline.h b/pw_sync_threadx/public/pw_sync_threadx/spin_lock_inline.h
index af81d78..ae08b0d 100644
--- a/pw_sync_threadx/public/pw_sync_threadx/spin_lock_inline.h
+++ b/pw_sync_threadx/public/pw_sync_threadx/spin_lock_inline.h
@@ -17,8 +17,8 @@
 
 namespace pw::sync {
 
-inline SpinLock::SpinLock()
-    : native_type_{.locked = false, .saved_interrupt_mask = 0} {}
+constexpr SpinLock::SpinLock()
+    : native_type_{.locked{false}, .saved_interrupt_mask = 0} {}
 
 inline SpinLock::native_handle_type SpinLock::native_handle() {
   return native_type_;