aboutsummaryrefslogtreecommitdiff
path: root/pw_sync_freertos
diff options
context:
space:
mode:
authorEwout van Bekkum <ewout@google.com>2021-06-22 14:26:55 -0700
committerCQ Bot Account <pigweed-scoped@luci-project-accounts.iam.gserviceaccount.com>2021-06-22 23:58:21 +0000
commit25fd893156f43734751f3f3a6529cb1cbbc89c1b (patch)
treecc3158674cd2bb9de43172de8b58136abc1fb3e5 /pw_sync_freertos
parent878b735175b30c5be55f83ee3c1a2a94c5ba2c6a (diff)
downloadpigweed-25fd893156f43734751f3f3a6529cb1cbbc89c1b.tar.gz
pw_sync_freertos: remove unnecessary atomic in InterruptSpinLock
Changes the internal InterruptSpinLock locked state to use a plain bool instead of an atomic bool as an atomic is not necessary. Change-Id: I15fec5bd99861361a2ddbea98192447d09d17e79 Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/50464 Pigweed-Auto-Submit: Ewout van Bekkum <ewout@google.com> Commit-Queue: Ewout van Bekkum <ewout@google.com> Reviewed-by: Wyatt Hepler <hepler@google.com>
Diffstat (limited to 'pw_sync_freertos')
-rw-r--r--pw_sync_freertos/interrupt_spin_lock.cc12
-rw-r--r--pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_inline.h2
-rw-r--r--pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_native.h4
3 files changed, 8 insertions, 10 deletions
diff --git a/pw_sync_freertos/interrupt_spin_lock.cc b/pw_sync_freertos/interrupt_spin_lock.cc
index 656b05c60..825afc473 100644
--- a/pw_sync_freertos/interrupt_spin_lock.cc
+++ b/pw_sync_freertos/interrupt_spin_lock.cc
@@ -27,15 +27,15 @@ void InterruptSpinLock::lock() {
taskENTER_CRITICAL();
}
// We can't deadlock here so crash instead.
- PW_CHECK(!native_type_.locked.load(std::memory_order_relaxed),
+ PW_CHECK(!native_type_.locked,
"Recursive InterruptSpinLock::lock() detected");
- native_type_.locked.store(true, std::memory_order_relaxed);
+ native_type_.locked = true;
}
bool InterruptSpinLock::try_lock() {
if (interrupt::InInterruptContext()) {
UBaseType_t saved_interrupt_mask = taskENTER_CRITICAL_FROM_ISR();
- if (native_type_.locked.load(std::memory_order_relaxed)) {
+ if (native_type_.locked) {
// Already locked, restore interrupts and bail out.
taskEXIT_CRITICAL_FROM_ISR(saved_interrupt_mask);
return false;
@@ -43,18 +43,18 @@ bool InterruptSpinLock::try_lock() {
native_type_.saved_interrupt_mask = saved_interrupt_mask;
} else { // Task context
taskENTER_CRITICAL();
- if (native_type_.locked.load(std::memory_order_relaxed)) {
+ if (native_type_.locked) {
// ALready locked, restore interrupts and bail out.
taskEXIT_CRITICAL();
return false;
}
}
- native_type_.locked.store(true, std::memory_order_relaxed);
+ native_type_.locked = true;
return true;
}
void InterruptSpinLock::unlock() {
- native_type_.locked.store(false, std::memory_order_relaxed);
+ native_type_.locked = false;
if (interrupt::InInterruptContext()) {
taskEXIT_CRITICAL_FROM_ISR(native_type_.saved_interrupt_mask);
} else { // Task context
diff --git a/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_inline.h b/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_inline.h
index 8bbd4cfd8..f086d1549 100644
--- a/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_inline.h
+++ b/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_inline.h
@@ -18,7 +18,7 @@
namespace pw::sync {
constexpr InterruptSpinLock::InterruptSpinLock()
- : native_type_{.locked{false}, .saved_interrupt_mask = 0} {}
+ : native_type_{.locked = false, .saved_interrupt_mask = 0} {}
inline InterruptSpinLock::native_handle_type
InterruptSpinLock::native_handle() {
diff --git a/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_native.h b/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_native.h
index ac476dc8a..e7f0e8f09 100644
--- a/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_native.h
+++ b/pw_sync_freertos/public/pw_sync_freertos/interrupt_spin_lock_native.h
@@ -13,14 +13,12 @@
// the License.
#pragma once
-#include <atomic>
-
#include "FreeRTOS.h"
namespace pw::sync::backend {
struct NativeInterruptSpinLock {
- std::atomic<bool> locked; // Used to detect recursion.
+ bool locked; // Used to detect recursion.
UBaseType_t saved_interrupt_mask;
};
using NativeInterruptSpinLockHandle = NativeInterruptSpinLock&;