1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
use super::core::*;
use super::queue_state::*;
use super::job_queue::*;
use std::sync::*;
use futures::task::{ArcWake};
///
/// Waker that will wake the specified queue in the specified scheduler core
///
pub (super) struct WakeQueue(pub (super) Arc<JobQueue>, pub (super) Arc<SchedulerCore>);
impl ArcWake for WakeQueue {
fn wake_by_ref(arc_self: &Arc<Self>) {
// Decompose this structure
let WakeQueue(ref queue, ref core) = **arc_self;
// Move the queue to the idle state if we can
{
let mut queue_core = queue.core.lock().unwrap();
// Queue can be woken if it's in the WaitingForWake state
match queue_core.state {
QueueState::WaitingForUnpark => {
// Assume that this was part of a DoubleWake that has become stale (woke up, reached a park, created a WakeThread for notifications)
queue_core.state = QueueState::WaitingForUnpark;
return;
},
QueueState::WaitingForWake => queue_core.state = QueueState::Idle,
QueueState::Running => queue_core.state = QueueState::AwokenWhileRunning,
other_state => queue_core.state = other_state
}
}
// Cause the core to reschedule its events
core.reschedule_queue(queue, Arc::clone(core));
}
}