From 91aaea761e5ab6117fb3613d5e0e20308ee65343 Mon Sep 17 00:00:00 2001 From: Dario Nieuwenhuis Date: Sat, 20 Feb 2021 01:43:10 +0100 Subject: [PATCH] Use Relaxed atomics with fence instead of SeqCst --- embassy-nrf/src/rtc.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/embassy-nrf/src/rtc.rs b/embassy-nrf/src/rtc.rs index 079e9b32..1ddc460e 100644 --- a/embassy-nrf/src/rtc.rs +++ b/embassy-nrf/src/rtc.rs @@ -1,6 +1,6 @@ use core::cell::Cell; use core::ops::Deref; -use core::sync::atomic::{AtomicU32, Ordering}; +use core::sync::atomic::{compiler_fence, AtomicU32, Ordering}; use embassy::time::Clock; @@ -143,7 +143,7 @@ impl RTC { fn next_period(&self) { interrupt::free(|cs| { - let period = self.period.fetch_add(1, Ordering::SeqCst) + 1; + let period = self.period.fetch_add(1, Ordering::Relaxed) + 1; let t = (period as u64) << 23; for n in 0..ALARM_COUNT { @@ -231,7 +231,8 @@ impl RTC { impl embassy::time::Clock for RTC { fn now(&self) -> u64 { // `period` MUST be read before `counter`, see comment at the top for details. - let period = self.period.load(Ordering::SeqCst); + let period = self.period.load(Ordering::Relaxed); + compiler_fence(Ordering::Acquire); let counter = self.rtc.counter.read().bits(); calc_now(period, counter) }