From 9bf02699bfe949a6386a529e6d6105ef8e81ab0a Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 17 May 2023 11:03:53 -0700 Subject: [PATCH] wip --- .../runtime/scheduler/multi_thread/worker.rs | 22 +++++++++++++------ 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/tokio/src/runtime/scheduler/multi_thread/worker.rs b/tokio/src/runtime/scheduler/multi_thread/worker.rs index 75d701b0f..d06acde53 100644 --- a/tokio/src/runtime/scheduler/multi_thread/worker.rs +++ b/tokio/src/runtime/scheduler/multi_thread/worker.rs @@ -93,6 +93,8 @@ struct Core { /// The worker-local run queue. run_queue: queue::Local>, + lifo: Lifo, + /// True if the worker is currently searching for more work. Searching /// involves attempting to steal from other workers. is_searching: bool, @@ -113,6 +115,9 @@ struct Core { rand: FastRand, } +unsafe impl Send for Core {} +unsafe impl Sync for Core {} + /// State shared across all workers pub(super) struct Shared { /// Per-worker remote state. All other workers have access to this and is @@ -210,10 +215,17 @@ pub(super) fn create( let unpark = park.unpark(); let metrics = WorkerMetrics::from_config(&config); + remotes.push(Remote { + lifo_slot: task::AtomicCell::new(), + steal, + unpark, + }); + cores.push(Box::new(Core { index: i, tick: 0, run_queue, + lifo: task::AtomicCell::new(), is_searching: false, is_shutdown: false, park: Some(park), @@ -221,11 +233,6 @@ pub(super) fn create( rand: FastRand::new(config.seed_generator.next_seed()), })); - remotes.push(Remote { - lifo_slot: task::AtomicCell::new(), - steal, - unpark, - }); worker_metrics.push(metrics); } @@ -756,8 +763,9 @@ impl Core { park.shutdown(&handle.driver); } - fn lifo_slot<'a>(&self, handle: &'a Handle) -> &'a Lifo { - &handle.shared.remotes[self.index].lifo_slot + fn lifo_slot<'a>(&'a self, handle: &'a Handle) -> &'a Lifo { + // &handle.shared.remotes[self.index].lifo_slot + &self.lifo } }