refactor: Remove wrapping cell

mio-0-7
k-nasa 5 years ago
parent 11ee2a8985
commit 088aa5662c

@ -219,7 +219,7 @@ impl Machine {
runs = 0; runs = 0;
rt.quick_poll().unwrap(); rt.quick_poll().unwrap();
let p = self.processor.lock(); let mut p = self.processor.lock();
if let Steal::Success(task) = p.steal_from_global(rt) { if let Steal::Success(task) = p.steal_from_global(rt) {
p.schedule(rt, task); p.schedule(rt, task);
} }
@ -284,7 +284,7 @@ struct Processor {
worker: Worker<Runnable>, worker: Worker<Runnable>,
/// Contains the next task to run as an optimization that skips the queue. /// Contains the next task to run as an optimization that skips the queue.
slot: Cell<Option<Runnable>>, slot: Option<Runnable>,
} }
impl Processor { impl Processor {
@ -292,13 +292,13 @@ impl Processor {
fn new() -> Processor { fn new() -> Processor {
Processor { Processor {
worker: Worker::new_fifo(), worker: Worker::new_fifo(),
slot: Cell::new(None), slot: None,
} }
} }
/// Schedules a task to run on this processor. /// Schedules a task to run on this processor.
fn schedule(&self, rt: &Runtime, task: Runnable) { fn schedule(&mut self, rt: &Runtime, task: Runnable) {
match self.slot.replace(Some(task)) { match self.slot.replace(task) {
None => {} None => {}
Some(task) => { Some(task) => {
self.worker.push(task); self.worker.push(task);
@ -308,7 +308,7 @@ impl Processor {
} }
/// Flushes a task from the slot into the local queue. /// Flushes a task from the slot into the local queue.
fn flush_slot(&self, rt: &Runtime) { fn flush_slot(&mut self, rt: &Runtime) {
if let Some(task) = self.slot.take() { if let Some(task) = self.slot.take() {
self.worker.push(task); self.worker.push(task);
rt.notify(); rt.notify();
@ -316,7 +316,7 @@ impl Processor {
} }
/// Pops a task from this processor. /// Pops a task from this processor.
fn pop_task(&self) -> Option<Runnable> { fn pop_task(&mut self) -> Option<Runnable> {
self.slot.take().or_else(|| self.worker.pop()) self.slot.take().or_else(|| self.worker.pop())
} }

Loading…
Cancel
Save