mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
or how about this...?
This commit is contained in:
@@ -150,6 +150,12 @@ impl Idle {
|
|||||||
lock.idle.sleepers.contains(&worker_id)
|
lock.idle.sleepers.contains(&worker_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Returns `true` if all other workers are currently parked.
|
||||||
|
pub(super) fn all_parked(&self) -> bool {
|
||||||
|
let state = State(self.state.fetch_add(0, SeqCst));
|
||||||
|
state.num_unparked() <= 1
|
||||||
|
}
|
||||||
|
|
||||||
fn notify_should_wakeup(&self) -> bool {
|
fn notify_should_wakeup(&self) -> bool {
|
||||||
let state = State(self.state.fetch_add(0, SeqCst));
|
let state = State(self.state.fetch_add(0, SeqCst));
|
||||||
state.num_searching() == 0 && state.num_unparked() < self.num_workers
|
state.num_searching() == 0 && state.num_unparked() < self.num_workers
|
||||||
|
|||||||
@@ -1352,8 +1352,6 @@ impl Handle {
|
|||||||
let should_notify = if is_yield || !core.lifo_enabled {
|
let should_notify = if is_yield || !core.lifo_enabled {
|
||||||
core.run_queue
|
core.run_queue
|
||||||
.push_back_or_overflow(task, self, &mut core.stats);
|
.push_back_or_overflow(task, self, &mut core.stats);
|
||||||
// Always notify another parked worker when pushing a yielded task
|
|
||||||
// to the main run queue if we are not currently parked.
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
// Push to the LIFO slot
|
// Push to the LIFO slot
|
||||||
@@ -1362,19 +1360,9 @@ impl Handle {
|
|||||||
// to be pushed to the back of the run queue.
|
// to be pushed to the back of the run queue.
|
||||||
core.run_queue
|
core.run_queue
|
||||||
.push_back_or_overflow(prev, self, &mut core.stats);
|
.push_back_or_overflow(prev, self, &mut core.stats);
|
||||||
// We have pushed the previous LIFO task to the back of the run
|
|
||||||
// queue, so we should attempt to notify another worker if we
|
|
||||||
// are not currently parked.
|
|
||||||
true
|
true
|
||||||
} else {
|
} else {
|
||||||
// If the scheduled task was pushed to the LIFO slot and there
|
self.shared.idle.all_parked()
|
||||||
// is no other task previously in the slot, skip notifying
|
|
||||||
// another worker, so that we can preferentially poll the LIFO
|
|
||||||
// task next. It can still be stolen if another worker is
|
|
||||||
// searching. This reduces cross thread notifications, and
|
|
||||||
// reduces the chance of the LIFO task moving across threads if
|
|
||||||
// the next poll is short.
|
|
||||||
false
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user