Skip to content

Commit

Permalink
replace Acquire and Release with Releaxed Ordering for the atomic ope…
Browse files Browse the repository at this point in the history
…rations
  • Loading branch information
hozan23 committed Jul 16, 2024
1 parent 0c04192 commit 48cfbd1
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,21 @@ impl<T> Inner<T> {
///
/// Result is used here instead of Cow because we don't have a Clone bound on T.
fn try_recv_at(&mut self, pos: &AtomicU64) -> Result<Result<T, &T>, TryRecvError> {
let i = pos.load(Ordering::Acquire);
let i = pos.load(Ordering::Relaxed);
let i = match i.checked_sub(self.head_pos) {
Some(i) => i
.try_into()
.expect("Head position more than usize::MAX behind a receiver"),
None => {
let count = self.head_pos - pos.load(Ordering::Relaxed);
pos.store(self.head_pos, Ordering::Release);
pos.store(self.head_pos, Ordering::Relaxed);
return Err(TryRecvError::Overflowed(count));
}
};

let last_waiter;
if let Some((_elt, waiters)) = self.queue.get_mut(i) {
pos.fetch_add(1, Ordering::Release);
pos.fetch_add(1, Ordering::Relaxed);
*waiters -= 1;
last_waiter = *waiters == 0;
} else {
Expand Down

0 comments on commit 48cfbd1

Please sign in to comment.