From 97587cb1fc977f6ecef94f7299d17533d1a1d02a Mon Sep 17 00:00:00 2001 From: prabhukr Date: Fri, 27 Dec 2024 13:53:55 -0800 Subject: [PATCH] pw_sync_freertos: Handle nodiscard return value MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ignoring the return values of types annotated with [[nodiscard]] attribute creates a warning in newer versions of Clang. Adding local variables to handle the return values. Bug: 366374135 Change-Id: I59983e71acba0004619dffdef6be41a87b85cab7 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/256695 Reviewed-by: Leonard Chan Reviewed-by: Aaron Green Commit-Queue: Prabhu Karthikeyan Rajasekaran Docs-Not-Needed: Aaron Green Lint: Lint 🤖 --- pw_sync_freertos/timed_thread_notification.cc | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pw_sync_freertos/timed_thread_notification.cc b/pw_sync_freertos/timed_thread_notification.cc index ee75a5b9c2..771eba25f8 100644 --- a/pw_sync_freertos/timed_thread_notification.cc +++ b/pw_sync_freertos/timed_thread_notification.cc @@ -61,15 +61,16 @@ bool TimedThreadNotification::try_acquire_until( PW_DCHECK(xTaskNotifyStateClear(nullptr) == pdFALSE); { - std::lock_guard lock(native_handle().shared_spin_lock); - const bool notified = native_handle().notified; + auto handle = native_handle(); + std::lock_guard lock(handle.shared_spin_lock); + const bool notified = handle.notified; // Don't block if we've already reached the specified deadline time. if (notified || (SystemClock::now() >= deadline)) { - native_handle().notified = false; + handle.notified = false; return notified; } // Not notified yet, set the task handle for a one-time notification. - native_handle().blocked_thread = xTaskGetCurrentTaskHandle(); + handle.blocked_thread = xTaskGetCurrentTaskHandle(); } // xTaskNotifyWait may spuriously return pdFALSE due to vTaskSuspend & @@ -86,7 +87,8 @@ bool TimedThreadNotification::try_acquire_until( } } - std::lock_guard lock(native_handle().shared_spin_lock); + auto handle = native_handle(); + std::lock_guard lock(handle.shared_spin_lock); // We need to clear the thread notification state in case we were // notified after timing out but before entering this critical section. #ifdef configTASK_NOTIFICATION_ARRAY_ENTRIES @@ -99,9 +101,9 @@ bool TimedThreadNotification::try_acquire_until( // the loop above, we instead read it in this subsequent critical section in // order to also include notifications which arrived after we timed out but // before we entered this critical section. - const bool notified = native_handle().notified; - native_handle().notified = false; - native_handle().blocked_thread = nullptr; + const bool notified = handle.notified; + handle.notified = false; + handle.blocked_thread = nullptr; return notified; }