From aea5da101d1ddcc75d43144fc0f36e2e85cc542c Mon Sep 17 00:00:00 2001 From: Weijia Jiang Date: Wed, 13 Sep 2023 21:51:34 +0800 Subject: [PATCH] change ordering of atomic --- tokio/src/runtime/task/list.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/tokio/src/runtime/task/list.rs b/tokio/src/runtime/task/list.rs index 27c8d1c560e..ab1aad7b168 100644 --- a/tokio/src/runtime/task/list.rs +++ b/tokio/src/runtime/task/list.rs @@ -115,7 +115,7 @@ impl OwnedTasks { 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; } @@ -127,7 +127,7 @@ impl OwnedTasks { fn push_inner(&self, task_id: super::Id, task: Task) { 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 @@ -151,7 +151,7 @@ impl OwnedTasks { { // 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); @@ -173,7 +173,7 @@ impl OwnedTasks { 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, @@ -204,7 +204,7 @@ impl OwnedTasks { .remove(task.header_ptr()) { Some(task) => { - self.count.fetch_sub(1, Ordering::Relaxed); + self.count.fetch_sub(1, Ordering::Release); Some(task) } None => None, @@ -212,7 +212,7 @@ impl OwnedTasks { } pub(crate) fn is_empty(&self) -> bool { - self.count.load(Ordering::SeqCst) == 0 + self.count.load(Ordering::Acquire) == 0 } }