diff options
| author | Dario Nieuwenhuis <[email protected]> | 2021-02-20 01:43:10 +0100 |
|---|---|---|
| committer | Dario Nieuwenhuis <[email protected]> | 2021-02-20 01:43:10 +0100 |
| commit | 91aaea761e5ab6117fb3613d5e0e20308ee65343 (patch) | |
| tree | 009d0acc424a560177cb5effcc14fa26816f8bd2 | |
| parent | 406f3b7cbf2242be2e455a748352265cfb65f750 (diff) | |
Use Relaxed atomics with fence instead of SeqCst
| -rw-r--r-- | embassy-nrf/src/rtc.rs | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs index 079e9b324..1ddc460e2 100644 --- a/embassy-nrf/src/rtc.rs +++ b/embassy-nrf/src/rtc.rs | |||
| @@ -1,6 +1,6 @@ | |||
| 1 | use core::cell::Cell; | 1 | use core::cell::Cell; |
| 2 | use core::ops::Deref; | 2 | use core::ops::Deref; |
| 3 | use core::sync::atomic::{AtomicU32, Ordering}; | 3 | use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; |
| 4 | 4 | ||
| 5 | use embassy::time::Clock; | 5 | use embassy::time::Clock; |
| 6 | 6 | ||
| @@ -143,7 +143,7 @@ impl<T: Instance> RTC<T> { | |||
| 143 | 143 | ||
| 144 | fn next_period(&self) { | 144 | fn next_period(&self) { |
| 145 | interrupt::free(|cs| { | 145 | interrupt::free(|cs| { |
| 146 | let period = self.period.fetch_add(1, Ordering::SeqCst) + 1; | 146 | let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; |
| 147 | let t = (period as u64) << 23; | 147 | let t = (period as u64) << 23; |
| 148 | 148 | ||
| 149 | for n in 0..ALARM_COUNT { | 149 | for n in 0..ALARM_COUNT { |
| @@ -231,7 +231,8 @@ impl<T: Instance> RTC<T> { | |||
| 231 | impl<T: Instance> embassy::time::Clock for RTC<T> { | 231 | impl<T: Instance> embassy::time::Clock for RTC<T> { |
| 232 | fn now(&self) -> u64 { | 232 | fn now(&self) -> u64 { |
| 233 | // `period` MUST be read before `counter`, see comment at the top for details. | 233 | // `period` MUST be read before `counter`, see comment at the top for details. |
| 234 | let period = self.period.load(Ordering::SeqCst); | 234 | let period = self.period.load(Ordering::Relaxed); |
| 235 | compiler_fence(Ordering::Acquire); | ||
| 235 | let counter = self.rtc.counter.read().bits(); | 236 | let counter = self.rtc.counter.read().bits(); |
| 236 | calc_now(period, counter) | 237 | calc_now(period, counter) |
| 237 | } | 238 | } |
