Skip to content

Commit

Permalink
Change task_num to len based on the annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
hidva committed Jun 9, 2023
1 parent 04b6f38 commit f234563
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 10 deletions.
7 changes: 2 additions & 5 deletions tokio/src/runtime/scheduler/multi_thread/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,8 @@ pub(crate) fn local<T: 'static>() -> (Steal<T>, Local<T>) {

impl<T> Local<T> {
/// Returns the number of entries in the queue
pub(crate) fn tasks_num(&self) -> (usize /* stealable */, usize /* total */) {
let n = self.inner.len() as usize;
// I'm not sure if it's really necessary to return a tuple, but based on has_tasks's comments,
// it seems that there may be tasks in queue that cannot be stolen?
(n, n)
pub(crate) fn len(&self) -> usize {
self.inner.len() as usize
}

/// How many tasks can be pushed into the queue
Expand Down
6 changes: 1 addition & 5 deletions tokio/src/runtime/scheduler/multi_thread/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -854,11 +854,7 @@ impl Core {
if self.is_searching {
return false;
}
let (stealable_tasks, total_tasks) = self.run_queue.tasks_num();
if stealable_tasks == 0 {
return false;
}
self.lifo_slot.is_some() as usize + (total_tasks - stealable_tasks) > 0
self.lifo_slot.is_some() as usize + self.run_queue.len() > 1
}

/// Prepares the worker state for parking.
Expand Down

0 comments on commit f234563

Please sign in to comment.