strengthen signals-received atomics (#5132)

* strengthen signals-received atomics

* Update node/overseer/overseer-gen/src/lib.rs

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>

* fmt

Co-authored-by: Andrei Sandu <54316454+sandreim@users.noreply.github.com>
This commit is contained in:
Robert Habermeier
2022-03-16 10:40:32 -05:00
committed by GitHub
parent a69330f081
commit 1d695612c4
@@ -196,13 +196,15 @@ pub struct SignalsReceived(Arc<AtomicUsize>);
impl SignalsReceived { impl SignalsReceived {
/// Load the current value of received signals. /// Load the current value of received signals.
pub fn load(&self) -> usize { pub fn load(&self) -> usize {
// off by a few is ok // It's imperative that we prevent reading a stale value from memory because of reordering.
self.0.load(atomic::Ordering::Relaxed) // Memory barrier to ensure that no reads or writes in the current thread before this load are reordered.
// All writes in other threads using release semantics become visible to the current thread.
self.0.load(atomic::Ordering::Acquire)
} }
/// Increase the number of signals by one. /// Increase the number of signals by one.
pub fn inc(&self) { pub fn inc(&self) {
self.0.fetch_add(1, atomic::Ordering::Acquire); self.0.fetch_add(1, atomic::Ordering::AcqRel);
} }
} }