Skip to content

Commit

Permalink
m: Weaken the atomic orderings for notification
Browse files Browse the repository at this point in the history
The atomic orderings on State::notified might be too strong, as it's primarily
being used as a deterrent against waking up too many threads. This PR weakens
their sequentially consistent operations to Acquire/Release.
  • Loading branch information
james7132 authored Feb 17, 2024
1 parent 568a314 commit 188f976
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ impl State {
fn notify(&self) {
if self
.notified
.compare_exchange(false, true, Ordering::SeqCst, Ordering::SeqCst)
.compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire)
.is_ok()
{
let waker = self.sleepers.lock().unwrap().notify();
Expand Down Expand Up @@ -672,7 +672,7 @@ impl Ticker<'_> {

self.state
.notified
.swap(sleepers.is_notified(), Ordering::SeqCst);
.store(sleepers.is_notified(), Ordering::Release);

true
}
Expand All @@ -685,7 +685,7 @@ impl Ticker<'_> {

self.state
.notified
.swap(sleepers.is_notified(), Ordering::SeqCst);
.store(sleepers.is_notified(), Ordering::Release);
}
self.sleeping = 0;
}
Expand Down Expand Up @@ -733,7 +733,7 @@ impl Drop for Ticker<'_> {

self.state
.notified
.swap(sleepers.is_notified(), Ordering::SeqCst);
.store(sleepers.is_notified(), Ordering::Release);

// If this ticker was notified, then notify another ticker.
if notified {
Expand Down

0 comments on commit 188f976

Please sign in to comment.