Skip to content

Commit 6719c48

Browse files
carllercheellenhp
authored andcommitted
rt: remove unnecessary enum in basic_scheduler (tokio-rs#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.
1 parent bffe436 commit 6719c48

File tree

1 file changed

+13
-39
lines changed

1 file changed

+13
-39
lines changed

tokio/src/runtime/basic_scheduler.rs

+13-39
Original file line numberDiff line numberDiff line change
@@ -64,23 +64,10 @@ pub(crate) struct Spawner {
6464
shared: Arc<Shared>,
6565
}
6666

67-
/// A remote scheduler entry.
68-
///
69-
/// These are filled in by remote threads sending instructions to the scheduler.
70-
enum RemoteMsg {
71-
/// A remote thread wants to spawn a task.
72-
Schedule(task::Notified<Arc<Shared>>),
73-
}
74-
75-
// Safety: Used correctly, the task header is "thread safe". Ultimately the task
76-
// is owned by the current thread executor, for which this instruction is being
77-
// sent.
78-
unsafe impl Send for RemoteMsg {}
79-
8067
/// Scheduler state shared between threads.
8168
struct Shared {
8269
/// Remote run queue. None if the `Runtime` has been dropped.
83-
queue: Mutex<Option<VecDeque<RemoteMsg>>>,
70+
queue: Mutex<Option<VecDeque<task::Notified<Arc<Shared>>>>>,
8471

8572
/// Collection of all active tasks spawned onto this executor.
8673
owned: OwnedTasks<Arc<Shared>>,
@@ -251,12 +238,8 @@ impl Drop for BasicScheduler {
251238
// Using `Option::take` to replace the shared queue with `None`.
252239
// We already shut down every task, so we just need to drop the task.
253240
if let Some(remote_queue) = remote_queue {
254-
for entry in remote_queue {
255-
match entry {
256-
RemoteMsg::Schedule(task) => {
257-
drop(task);
258-
}
259-
}
241+
for task in remote_queue {
242+
drop(task);
260243
}
261244
}
262245

@@ -396,7 +379,7 @@ impl Spawner {
396379
handle
397380
}
398381

399-
fn pop(&self) -> Option<RemoteMsg> {
382+
fn pop(&self) -> Option<task::Notified<Arc<Shared>>> {
400383
match self.shared.queue.lock().as_mut() {
401384
Some(queue) => queue.pop_front(),
402385
None => None,
@@ -470,7 +453,7 @@ impl Schedule for Arc<Shared> {
470453
// don't need to do anything with the notification in that case.
471454
let mut guard = self.queue.lock();
472455
if let Some(queue) = guard.as_mut() {
473-
queue.push_back(RemoteMsg::Schedule(task));
456+
queue.push_back(task);
474457
drop(guard);
475458
self.unpark.unpark();
476459
}
@@ -528,17 +511,12 @@ impl CoreGuard<'_> {
528511
core.tick = core.tick.wrapping_add(1);
529512

530513
let entry = if tick % REMOTE_FIRST_INTERVAL == 0 {
531-
core.spawner
532-
.pop()
533-
.or_else(|| core.tasks.pop_front().map(RemoteMsg::Schedule))
514+
core.spawner.pop().or_else(|| core.tasks.pop_front())
534515
} else {
535-
core.tasks
536-
.pop_front()
537-
.map(RemoteMsg::Schedule)
538-
.or_else(|| core.spawner.pop())
516+
core.tasks.pop_front().or_else(|| core.spawner.pop())
539517
};
540518

541-
let entry = match entry {
519+
let task = match entry {
542520
Some(entry) => entry,
543521
None => {
544522
core = context.park(core);
@@ -548,17 +526,13 @@ impl CoreGuard<'_> {
548526
}
549527
};
550528

551-
match entry {
552-
RemoteMsg::Schedule(task) => {
553-
let task = context.spawner.shared.owned.assert_owner(task);
529+
let task = context.spawner.shared.owned.assert_owner(task);
554530

555-
let (c, _) = context.run_task(core, || {
556-
task.run();
557-
});
531+
let (c, _) = context.run_task(core, || {
532+
task.run();
533+
});
558534

559-
core = c;
560-
}
561-
}
535+
core = c;
562536
}
563537

564538
// Yield to the driver, this drives the timer and pulls any

0 commit comments

Comments
 (0)