Skip to content

Commit

Permalink
change ordering of atomic
Browse files Browse the repository at this point in the history
  • Loading branch information
wathenjiang committed Sep 13, 2023
1 parent 632a8d3 commit aea5da1
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions tokio/src/runtime/task/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl<S: 'static> OwnedTasks<S> {
task.header().set_owner_id(self.id);
}
// check close flag
if self.closed.load(Ordering::Relaxed) {
if self.closed.load(Ordering::Acquire) {
task.shutdown();
return None;
}
Expand All @@ -127,7 +127,7 @@ impl<S: 'static> OwnedTasks<S> {
fn push_inner(&self, task_id: super::Id, task: Task<S>) {
let mut lock = self.lists[task_id.0 as usize & (self.grain - 1)].lock();
lock.list.push_front(task);
self.count.fetch_add(1, Ordering::Relaxed);
self.count.fetch_add(1, Ordering::Release);
}

/// Asserts that the given task is owned by this OwnedTasks and convert it to
Expand All @@ -151,7 +151,7 @@ impl<S: 'static> OwnedTasks<S> {
{
// The first iteration of the loop was unrolled so it can set the
// closed bool.
self.closed.fetch_and(true, Ordering::SeqCst);
self.closed.fetch_and(true, Ordering::Release);

for i in 0..self.lists.len() {
let first_task = self.pop_back_inner(i);
Expand All @@ -173,7 +173,7 @@ impl<S: 'static> OwnedTasks<S> {
debug_assert!(index < self.lists.len());
match self.lists[index].lock().list.pop_back() {
Some(task) => {
self.count.fetch_sub(1, Ordering::Relaxed);
self.count.fetch_sub(1, Ordering::Release);
Some(task)
}
None => None,
Expand Down Expand Up @@ -204,15 +204,15 @@ impl<S: 'static> OwnedTasks<S> {
.remove(task.header_ptr())
{
Some(task) => {
self.count.fetch_sub(1, Ordering::Relaxed);
self.count.fetch_sub(1, Ordering::Release);
Some(task)
}
None => None,
}
}

pub(crate) fn is_empty(&self) -> bool {
self.count.load(Ordering::SeqCst) == 0
self.count.load(Ordering::Acquire) == 0
}
}

Expand Down

0 comments on commit aea5da1

Please sign in to comment.