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 6453017
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions tokio/src/runtime/scheduler/current_thread/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ fn shutdown2(mut core: Box<Core>, handle: &Handle) -> Box<Core> {
drop(task);
}

assert!(handle.shared.owned.is_closed());
assert!(handle.shared.owned.is_empty());

// Submit metrics
Expand Down
1 change: 1 addition & 0 deletions tokio/src/runtime/scheduler/multi_thread/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1152,6 +1152,7 @@ impl Handle {
return;
}

debug_assert!(self.shared.owned.is_closed());
debug_assert!(self.shared.owned.is_empty());

for mut core in cores.drain(..) {
Expand Down
10 changes: 7 additions & 3 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 Down Expand Up @@ -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 Down Expand Up @@ -211,8 +211,12 @@ impl<S: 'static> OwnedTasks<S> {
}
}

pub(crate) fn is_closed(&self) -> bool {
self.closed.load(Ordering::Acquire)
}

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

Expand Down
2 changes: 1 addition & 1 deletion tokio/src/runtime/tests/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ impl Runtime {
}

drop(core);

assert!(self.0.owned.is_closed());
assert!(self.0.owned.is_empty());
}
}
Expand Down

0 comments on commit 6453017

Please sign in to comment.