noexcept: add some noexcepts when mirroring the STL Change-Id: If139a17461644afd0262710631ca413f38f2f66e Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/31040 Commit-Queue: Ewout van Bekkum <ewout@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
diff --git a/pw_chrono/public/pw_chrono/system_clock.h b/pw_chrono/public/pw_chrono/system_clock.h index 9cd6eae..36481c2 100644 --- a/pw_chrono/public/pw_chrono/system_clock.h +++ b/pw_chrono/public/pw_chrono/system_clock.h
@@ -99,7 +99,7 @@ static constexpr bool is_nmi_safe = backend::kSystemClockNmiSafe; // This is thread and IRQ safe. This must be provided by the backend. - static time_point now() { + static time_point now() noexcept { return time_point(duration(backend::GetSystemClockTickCount())); } };
diff --git a/pw_sync/public/pw_sync/binary_semaphore.h b/pw_sync/public/pw_sync/binary_semaphore.h index 53925d3..4886b34 100644 --- a/pw_sync/public/pw_sync/binary_semaphore.h +++ b/pw_sync/public/pw_sync/binary_semaphore.h
@@ -65,7 +65,7 @@ // Attempts to decrement by the internal counter to 0 without blocking. // Returns true if the internal counter was reset successfully. // This is IRQ safe. - bool try_acquire(); + bool try_acquire() noexcept; // Attempts to decrement the internal counter to 0 where, if needed, blocking // for at least the specified duration. @@ -79,7 +79,9 @@ // This is thread safe. bool try_acquire_until(chrono::SystemClock::time_point until_at_least); - static constexpr ptrdiff_t max() { return backend::kBinarySemaphoreMaxValue; } + static constexpr ptrdiff_t max() noexcept { + return backend::kBinarySemaphoreMaxValue; + } native_handle_type native_handle();
diff --git a/pw_sync/public/pw_sync/counting_semaphore.h b/pw_sync/public/pw_sync/counting_semaphore.h index 18dee02..a7b94f6 100644 --- a/pw_sync/public/pw_sync/counting_semaphore.h +++ b/pw_sync/public/pw_sync/counting_semaphore.h
@@ -65,7 +65,7 @@ // Attempts to decrement by the internal counter by 1 without blocking. // Returns true if the internal counter was decremented successfully. // This is IRQ safe. - bool try_acquire(); + bool try_acquire() noexcept; // Attempts to decrement the internal counter by 1 where, if needed, blocking // for at least the specified duration. @@ -79,7 +79,7 @@ // This is thread safe. bool try_acquire_until(chrono::SystemClock::time_point until_at_least); - static constexpr ptrdiff_t max() { + static constexpr ptrdiff_t max() noexcept { return backend::kCountingSemaphoreMaxValue; }
diff --git a/pw_sync_freertos/public/pw_sync_freertos/binary_semaphore_inline.h b/pw_sync_freertos/public/pw_sync_freertos/binary_semaphore_inline.h index eab8d02..8a3562a 100644 --- a/pw_sync_freertos/public/pw_sync_freertos/binary_semaphore_inline.h +++ b/pw_sync_freertos/public/pw_sync_freertos/binary_semaphore_inline.h
@@ -59,7 +59,7 @@ #endif // INCLUDE_vTaskSuspend } -inline bool BinarySemaphore::try_acquire() { +inline bool BinarySemaphore::try_acquire() noexcept { if (interrupt::InInterruptContext()) { BaseType_t woke_higher_task = pdFALSE; const bool success =
diff --git a/pw_sync_freertos/public/pw_sync_freertos/counting_semaphore_inline.h b/pw_sync_freertos/public/pw_sync_freertos/counting_semaphore_inline.h index 8a293d2..9a3e95b 100644 --- a/pw_sync_freertos/public/pw_sync_freertos/counting_semaphore_inline.h +++ b/pw_sync_freertos/public/pw_sync_freertos/counting_semaphore_inline.h
@@ -48,7 +48,7 @@ #endif // INCLUDE_vTaskSuspend } -inline bool CountingSemaphore::try_acquire() { +inline bool CountingSemaphore::try_acquire() noexcept { if (interrupt::InInterruptContext()) { BaseType_t woke_higher_task = pdFALSE; const bool success =
diff --git a/pw_sync_stl/binary_semaphore.cc b/pw_sync_stl/binary_semaphore.cc index f1f3fb4..fdff483 100644 --- a/pw_sync_stl/binary_semaphore.cc +++ b/pw_sync_stl/binary_semaphore.cc
@@ -33,7 +33,7 @@ native_type_.count = 0; } -bool BinarySemaphore::try_acquire() { +bool BinarySemaphore::try_acquire() noexcept { std::lock_guard lock(native_type_.mutex); if (native_type_.count != 0) { native_type_.count = 0;
diff --git a/pw_sync_stl/counting_semaphore.cc b/pw_sync_stl/counting_semaphore.cc index 781aa77..629d0dc 100644 --- a/pw_sync_stl/counting_semaphore.cc +++ b/pw_sync_stl/counting_semaphore.cc
@@ -36,7 +36,7 @@ --native_type_.count; } -bool CountingSemaphore::try_acquire() { +bool CountingSemaphore::try_acquire() noexcept { std::lock_guard lock(native_type_.mutex); if (native_type_.count != 0) { --native_type_.count;
diff --git a/pw_sync_threadx/public/pw_sync_threadx/binary_semaphore_inline.h b/pw_sync_threadx/public/pw_sync_threadx/binary_semaphore_inline.h index f0df039..7fa8dcd 100644 --- a/pw_sync_threadx/public/pw_sync_threadx/binary_semaphore_inline.h +++ b/pw_sync_threadx/public/pw_sync_threadx/binary_semaphore_inline.h
@@ -50,7 +50,7 @@ PW_ASSERT(result == TX_SUCCESS); } -inline bool BinarySemaphore::try_acquire() { +inline bool BinarySemaphore::try_acquire() noexcept { const UINT result = tx_semaphore_get(&native_type_, TX_NO_WAIT); if (result == TX_NO_INSTANCE) { return false;
diff --git a/pw_sync_threadx/public/pw_sync_threadx/counting_semaphore_inline.h b/pw_sync_threadx/public/pw_sync_threadx/counting_semaphore_inline.h index 763baee..9dfd1ca 100644 --- a/pw_sync_threadx/public/pw_sync_threadx/counting_semaphore_inline.h +++ b/pw_sync_threadx/public/pw_sync_threadx/counting_semaphore_inline.h
@@ -51,7 +51,7 @@ PW_ASSERT(tx_semaphore_get(&native_type_, TX_WAIT_FOREVER) == TX_SUCCESS); } -inline bool CountingSemaphore::try_acquire() { +inline bool CountingSemaphore::try_acquire() noexcept { const UINT result = tx_semaphore_get(&native_type_, TX_NO_WAIT); if (result == TX_NO_INSTANCE) { return false;