From 6719c4859d54c2ab39b45522b0794553727e66e9 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Thu, 3 Feb 2022 09:14:22 -0800 Subject: [PATCH] rt: remove unnecessary enum in basic_scheduler (#4462) The enum is no longer needed. It was used previously to support multiple kinds of control messages to the scheduler but that has been refactored out. --- tokio/src/runtime/basic_scheduler.rs | 52 +++++++--------------------- 1 file changed, 13 insertions(+), 39 deletions(-) diff --git a/tokio/src/runtime/basic_scheduler.rs b/tokio/src/runtime/basic_scheduler.rs index 6eb7e8b2a28..401f55b3f2f 100644 --- a/tokio/src/runtime/basic_scheduler.rs +++ b/tokio/src/runtime/basic_scheduler.rs @@ -64,23 +64,10 @@ pub(crate) struct Spawner { shared: Arc, } -/// A remote scheduler entry. -/// -/// These are filled in by remote threads sending instructions to the scheduler. -enum RemoteMsg { - /// A remote thread wants to spawn a task. - Schedule(task::Notified>), -} - -// Safety: Used correctly, the task header is "thread safe". Ultimately the task -// is owned by the current thread executor, for which this instruction is being -// sent. -unsafe impl Send for RemoteMsg {} - /// Scheduler state shared between threads. struct Shared { /// Remote run queue. None if the `Runtime` has been dropped. - queue: Mutex>>, + queue: Mutex>>>>, /// Collection of all active tasks spawned onto this executor. owned: OwnedTasks>, @@ -251,12 +238,8 @@ impl Drop for BasicScheduler { // Using `Option::take` to replace the shared queue with `None`. // We already shut down every task, so we just need to drop the task. if let Some(remote_queue) = remote_queue { - for entry in remote_queue { - match entry { - RemoteMsg::Schedule(task) => { - drop(task); - } - } + for task in remote_queue { + drop(task); } } @@ -396,7 +379,7 @@ impl Spawner { handle } - fn pop(&self) -> Option { + fn pop(&self) -> Option>> { match self.shared.queue.lock().as_mut() { Some(queue) => queue.pop_front(), None => None, @@ -470,7 +453,7 @@ impl Schedule for Arc { // don't need to do anything with the notification in that case. let mut guard = self.queue.lock(); if let Some(queue) = guard.as_mut() { - queue.push_back(RemoteMsg::Schedule(task)); + queue.push_back(task); drop(guard); self.unpark.unpark(); } @@ -528,17 +511,12 @@ impl CoreGuard<'_> { core.tick = core.tick.wrapping_add(1); let entry = if tick % REMOTE_FIRST_INTERVAL == 0 { - core.spawner - .pop() - .or_else(|| core.tasks.pop_front().map(RemoteMsg::Schedule)) + core.spawner.pop().or_else(|| core.tasks.pop_front()) } else { - core.tasks - .pop_front() - .map(RemoteMsg::Schedule) - .or_else(|| core.spawner.pop()) + core.tasks.pop_front().or_else(|| core.spawner.pop()) }; - let entry = match entry { + let task = match entry { Some(entry) => entry, None => { core = context.park(core); @@ -548,17 +526,13 @@ impl CoreGuard<'_> { } }; - match entry { - RemoteMsg::Schedule(task) => { - let task = context.spawner.shared.owned.assert_owner(task); + let task = context.spawner.shared.owned.assert_owner(task); - let (c, _) = context.run_task(core, || { - task.run(); - }); + let (c, _) = context.run_task(core, || { + task.run(); + }); - core = c; - } - } + core = c; } // Yield to the driver, this drives the timer and pulls any