Skip to content

Commit

Permalink
pw_sync_freertos: Handle nodiscard return value
Browse files Browse the repository at this point in the history
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 <[email protected]>
Reviewed-by: Aaron Green <[email protected]>
Commit-Queue: Prabhu Karthikeyan Rajasekaran <[email protected]>
Docs-Not-Needed: Aaron Green <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
Prabhuk authored and CQ Bot Account committed Dec 27, 2024
1 parent a567ea4 commit 97587cb
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions pw_sync_freertos/timed_thread_notification.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 &
Expand All @@ -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
Expand All @@ -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;
}

Expand Down

0 comments on commit 97587cb

Please sign in to comment.