mirror of
https://github.com/tokio-rs/tokio.git
synced 2025-10-01 12:20:39 +00:00
wip
This commit is contained in:
parent
908ebc705a
commit
f6f54de2bf
@ -778,18 +778,39 @@ impl Worker {
|
|||||||
/// a new worker will actually try to steal. The idea is to make sure not all
|
/// a new worker will actually try to steal. The idea is to make sure not all
|
||||||
/// workers will be trying to steal at the same time.
|
/// workers will be trying to steal at the same time.
|
||||||
fn steal_work(&self, cx: &Context, core: &mut Core) -> Option<Notified> {
|
fn steal_work(&self, cx: &Context, core: &mut Core) -> Option<Notified> {
|
||||||
|
#[cfg(not(loom))]
|
||||||
|
const ROUNDS: usize = 4;
|
||||||
|
|
||||||
|
#[cfg(loom)]
|
||||||
|
const ROUNDS: usize = 1;
|
||||||
|
|
||||||
if !self.transition_to_searching(cx, core) {
|
if !self.transition_to_searching(cx, core) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
|
||||||
let num = cx.shared().remotes.len();
|
let num = cx.shared().remotes.len();
|
||||||
|
|
||||||
|
for i in 0..ROUNDS {
|
||||||
|
let last = ROUNDS - 1 == i;
|
||||||
|
|
||||||
// Start from a random worker
|
// Start from a random worker
|
||||||
let start = core.rand.fastrand_n(num as u32) as usize;
|
let start = core.rand.fastrand_n(num as u32) as usize;
|
||||||
|
|
||||||
self.steal_one_round(cx, core, start)
|
if let Some(task) = self.steal_one_round(cx, core, start, last) {
|
||||||
|
return Some(task);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn steal_one_round(&self, cx: &Context, core: &mut Core, start: usize) -> Option<Notified> {
|
None
|
||||||
|
}
|
||||||
|
|
||||||
|
fn steal_one_round(
|
||||||
|
&self,
|
||||||
|
cx: &Context,
|
||||||
|
core: &mut Core,
|
||||||
|
start: usize,
|
||||||
|
lifo: bool,
|
||||||
|
) -> Option<Notified> {
|
||||||
let num = cx.shared().remotes.len();
|
let num = cx.shared().remotes.len();
|
||||||
|
|
||||||
for i in 0..num {
|
for i in 0..num {
|
||||||
@ -1054,7 +1075,7 @@ impl Worker {
|
|||||||
// Before we park, if we are searching, we need to transition away from searching
|
// Before we park, if we are searching, we need to transition away from searching
|
||||||
if self.transition_from_searching(cx, &mut core) {
|
if self.transition_from_searching(cx, &mut core) {
|
||||||
// We were the last searching worker, we need to do one last check
|
// We were the last searching worker, we need to do one last check
|
||||||
if let Some(task) = self.steal_one_round(cx, &mut core, 0) {
|
if let Some(task) = self.steal_one_round(cx, &mut core, 0, true) {
|
||||||
cx.shared().notify_parked_local();
|
cx.shared().notify_parked_local();
|
||||||
|
|
||||||
return Ok((Some(task), core));
|
return Ok((Some(task), core));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user