Skip to content
Snippets Groups Projects
Commit 1d695612 authored by asynchronous rob's avatar asynchronous rob Committed by GitHub
Browse files

strengthen signals-received atomics (#5132)


* strengthen signals-received atomics

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

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

* fmt

Co-authored-by: default avatarAndrei Sandu <54316454+sandreim@users.noreply.github.com>
parent a69330f0
No related merge requests found
......@@ -196,13 +196,15 @@ pub struct SignalsReceived(Arc<AtomicUsize>);
impl SignalsReceived {
/// Load the current value of received signals.
pub fn load(&self) -> usize {
// off by a few is ok
self.0.load(atomic::Ordering::Relaxed)
// It's imperative that we prevent reading a stale value from memory because of reordering.
// 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.
pub fn inc(&self) {
self.0.fetch_add(1, atomic::Ordering::Acquire);
self.0.fetch_add(1, atomic::Ordering::AcqRel);
}
}
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment