diff --git a/pw_async_basic/dispatcher.cc b/pw_async_basic/dispatcher.cc index a0909fe181..d23c4bc2f8 100644 --- a/pw_async_basic/dispatcher.cc +++ b/pw_async_basic/dispatcher.cc @@ -14,6 +14,7 @@ #include "pw_async_basic/dispatcher.h" #include +#include #include "pw_chrono/system_clock.h" @@ -74,7 +75,7 @@ void BasicDispatcher::MaybeSleep() { } lock_.unlock(); if (wake_time.has_value()) { - timed_notification_.try_acquire_until(*wake_time); + std::ignore = timed_notification_.try_acquire_until(*wake_time); } else { timed_notification_.acquire(); } diff --git a/pw_log_rpc/public/pw_log_rpc/rpc_log_drain_thread.h b/pw_log_rpc/public/pw_log_rpc/rpc_log_drain_thread.h index e61c71c7c2..f3a6402f07 100644 --- a/pw_log_rpc/public/pw_log_rpc/rpc_log_drain_thread.h +++ b/pw_log_rpc/public/pw_log_rpc/rpc_log_drain_thread.h @@ -16,6 +16,7 @@ #include #include +#include #include "pw_chrono/system_clock.h" #include "pw_log_rpc/log_service.h" @@ -63,7 +64,8 @@ class RpcLogDrainThread : public thread::ThreadCore, chrono::SystemClock::duration::zero(); while (true) { if (drains_pending && min_delay.has_value()) { - ready_to_flush_notification_.try_acquire_for(min_delay.value()); + std::ignore = + ready_to_flush_notification_.try_acquire_for(min_delay.value()); } else { ready_to_flush_notification_.acquire(); } diff --git a/pw_sync/public/pw_sync/binary_semaphore.h b/pw_sync/public/pw_sync/binary_semaphore.h index c3e025deab..b5bfd08a0e 100644 --- a/pw_sync/public/pw_sync/binary_semaphore.h +++ b/pw_sync/public/pw_sync/binary_semaphore.h @@ -71,7 +71,7 @@ class BinarySemaphore { /// @retval true if the internal counter was reset successfully. /// /// This is thread and IRQ safe. - bool try_acquire() noexcept; + [[nodiscard]] bool try_acquire() noexcept; /// Tries to decrement the internal counter to 0. Blocks until the specified /// timeout has elapsed or the counter was decremented to 0, whichever comes @@ -80,7 +80,7 @@ class BinarySemaphore { /// @retval true if the internal counter was decremented successfully. /// /// This is thread safe, but not IRQ safe. - bool try_acquire_for(chrono::SystemClock::duration timeout); + [[nodiscard]] bool try_acquire_for(chrono::SystemClock::duration timeout); /// Tries to decrement the internal counter to 0. Blocks until the specified /// deadline has been reached or the counter was decremented to 0, whichever @@ -89,15 +89,16 @@ class BinarySemaphore { /// @retval true if the internal counter was decremented successfully. /// /// This is thread safe, but not IRQ safe. - bool try_acquire_until(chrono::SystemClock::time_point deadline); + [[nodiscard]] bool try_acquire_until( + chrono::SystemClock::time_point deadline); /// @retval backend::kBinarySemaphoreMaxValue the internal counter's maximum /// possible value. - static constexpr ptrdiff_t max() noexcept { + [[nodiscard]] static constexpr ptrdiff_t max() noexcept { return backend::kBinarySemaphoreMaxValue; } - native_handle_type native_handle(); + [[nodiscard]] native_handle_type native_handle(); private: /// This may be a wrapper around a native type with additional members. diff --git a/pw_sync/public/pw_sync/counting_semaphore.h b/pw_sync/public/pw_sync/counting_semaphore.h index b0ab876713..0231b2d172 100644 --- a/pw_sync/public/pw_sync/counting_semaphore.h +++ b/pw_sync/public/pw_sync/counting_semaphore.h @@ -72,7 +72,7 @@ class CountingSemaphore { /// Returns true if the internal counter was decremented successfully. /// /// This is IRQ safe. - bool try_acquire() noexcept; + [[nodiscard]] bool try_acquire() noexcept; /// Tries to decrement the internal counter by 1. Blocks until the specified /// timeout has elapsed or the counter was decremented by 1, whichever comes @@ -80,7 +80,7 @@ class CountingSemaphore { /// /// Returns true if the internal counter was decremented successfully. /// This is thread safe, but not IRQ safe. - bool try_acquire_for(chrono::SystemClock::duration timeout); + [[nodiscard]] bool try_acquire_for(chrono::SystemClock::duration timeout); /// Tries to decrement the internal counter by 1. Blocks until the specified /// deadline has been reached or the counter was decremented by 1, whichever @@ -89,10 +89,11 @@ class CountingSemaphore { /// Returns true if the internal counter was decremented successfully. /// /// This is thread safe, but not IRQ safe. - bool try_acquire_until(chrono::SystemClock::time_point deadline); + [[nodiscard]] bool try_acquire_until( + chrono::SystemClock::time_point deadline); /// Returns the internal counter's maximum possible value. - static constexpr ptrdiff_t max() noexcept { + [[nodiscard]] static constexpr ptrdiff_t max() noexcept { return backend::kCountingSemaphoreMaxValue; } diff --git a/pw_sync/public/pw_sync/interrupt_spin_lock.h b/pw_sync/public/pw_sync/interrupt_spin_lock.h index 996ad6de1f..39411d2dfb 100644 --- a/pw_sync/public/pw_sync/interrupt_spin_lock.h +++ b/pw_sync/public/pw_sync/interrupt_spin_lock.h @@ -65,7 +65,7 @@ class PW_LOCKABLE("pw::sync::InterruptSpinLock") InterruptSpinLock { /// Returns true if the spinlock was successfully acquired. /// /// @b Precondition: Recursive locking is undefined behavior. - bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); + [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); /// Unlocks the spinlock. Failures are fatal. /// @@ -73,7 +73,7 @@ class PW_LOCKABLE("pw::sync::InterruptSpinLock") InterruptSpinLock { /// The spinlock is held by the caller. void unlock() PW_UNLOCK_FUNCTION(); - native_handle_type native_handle(); + [[nodiscard]] native_handle_type native_handle(); private: /// This may be a wrapper around a native type with additional members. diff --git a/pw_sync/public/pw_sync/mutex.h b/pw_sync/public/pw_sync/mutex.h index 18729f5470..1a3ca56cb0 100644 --- a/pw_sync/public/pw_sync/mutex.h +++ b/pw_sync/public/pw_sync/mutex.h @@ -63,7 +63,7 @@ class PW_LOCKABLE("pw::sync::Mutex") Mutex { /// @b PRECONDITION: /// The lock isn't already held by this thread. Recursive locking is /// undefined behavior. - bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); + [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); /// Unlocks the mutex. Failures are fatal. /// @@ -71,7 +71,7 @@ class PW_LOCKABLE("pw::sync::Mutex") Mutex { /// The mutex is held by this thread. void unlock() PW_UNLOCK_FUNCTION(); - native_handle_type native_handle(); + [[nodiscard]] native_handle_type native_handle(); protected: /// Expose the NativeMutex directly to derived classes (TimedMutex) in case diff --git a/pw_sync/public/pw_sync/recursive_mutex.h b/pw_sync/public/pw_sync/recursive_mutex.h index 1c09a1929f..e21d8f93bd 100644 --- a/pw_sync/public/pw_sync/recursive_mutex.h +++ b/pw_sync/public/pw_sync/recursive_mutex.h @@ -59,12 +59,12 @@ class PW_LOCKABLE("pw::sync::RecursiveMutex") RecursiveMutex { // Attempts to lock the mutex in a non-blocking manner. // Returns true if the mutex was successfully acquired. - bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); + [[nodiscard]] bool try_lock() PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); // Unlocks the mutex. Failures are fatal. void unlock() PW_UNLOCK_FUNCTION(); - native_handle_type native_handle(); + [[nodiscard]] native_handle_type native_handle(); private: // This may be a wrapper around a native type with additional members. diff --git a/pw_sync/public/pw_sync/thread_notification.h b/pw_sync/public/pw_sync/thread_notification.h index 85e6e1b6ba..5dac24b509 100644 --- a/pw_sync/public/pw_sync/thread_notification.h +++ b/pw_sync/public/pw_sync/thread_notification.h @@ -61,7 +61,7 @@ class ThreadNotification { /// was reset successfully. /// /// @b IMPORTANT: This should only be used by a single consumer thread. - bool try_acquire(); + [[nodiscard]] bool try_acquire(); /// Notifies the thread in a saturating manner, setting the notification /// latch. @@ -74,7 +74,7 @@ class ThreadNotification { /// This is IRQ and thread safe. void release(); - native_handle_type native_handle(); + [[nodiscard]] native_handle_type native_handle(); private: /// This may be a wrapper around a native type with additional members. diff --git a/pw_sync/public/pw_sync/timed_mutex.h b/pw_sync/public/pw_sync/timed_mutex.h index 396f9b68d8..67317272a4 100644 --- a/pw_sync/public/pw_sync/timed_mutex.h +++ b/pw_sync/public/pw_sync/timed_mutex.h @@ -56,7 +56,7 @@ class TimedMutex : public Mutex { /// @b PRECONDITION: /// The lock isn't already held by this thread. Recursive locking is /// undefined behavior. - bool try_lock_for(chrono::SystemClock::duration timeout) + [[nodiscard]] bool try_lock_for(chrono::SystemClock::duration timeout) PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); /// Tries to lock the mutex. Blocks until specified deadline has been reached @@ -66,7 +66,7 @@ class TimedMutex : public Mutex { /// @b PRECONDITION: /// The lock isn't already held by this thread. Recursive locking is /// undefined behavior. - bool try_lock_until(chrono::SystemClock::time_point deadline) + [[nodiscard]] bool try_lock_until(chrono::SystemClock::time_point deadline) PW_EXCLUSIVE_TRYLOCK_FUNCTION(true); }; diff --git a/pw_sync/public/pw_sync/timed_thread_notification.h b/pw_sync/public/pw_sync/timed_thread_notification.h index 7b98b39d84..c15b5a1e2b 100644 --- a/pw_sync/public/pw_sync/timed_thread_notification.h +++ b/pw_sync/public/pw_sync/timed_thread_notification.h @@ -54,7 +54,7 @@ class TimedThreadNotification : public ThreadNotification { /// was reset successfully. /// /// @b IMPORTANT: This should only be used by a single consumer thread. - bool try_acquire_for(chrono::SystemClock::duration timeout); + [[nodiscard]] bool try_acquire_for(chrono::SystemClock::duration timeout); /// Blocks until the specified deadline time has been reached the thread has /// been notified (i.e. notification latch can be cleared because it was set), @@ -66,7 +66,8 @@ class TimedThreadNotification : public ThreadNotification { /// was reset successfully. /// /// @b IMPORTANT: This should only be used by a single consumer thread. - bool try_acquire_until(chrono::SystemClock::time_point deadline); + [[nodiscard]] bool try_acquire_until( + chrono::SystemClock::time_point deadline); }; } // namespace pw::sync