use std::mem; use std::sync::Arc; use arraydeque::ArrayDeque; use crossbeam_channel::Receiver; use spin::{Mutex, MutexGuard}; use super::constants::INORDER_QUEUE_SIZE; use super::runq::{RunQueue, ToKey}; pub struct InnerJob
{ // peer (used by worker to schedule/handle inorder queue), // when the peer is None, the job is complete peer: Option
, pub body: B, } pub struct Job
{
inner: Arc Clone for Job {
fn clone(&self) -> Job {
Job {
inner: self.inner.clone(),
}
}
}
impl Job {
pub fn new(peer: P, body: B) -> Job {
Job {
inner: Arc::new(Mutex::new(InnerJob {
peer: Some(peer),
body,
})),
}
}
}
impl Job {
/// Returns a mutex guard to the inner job if complete
pub fn complete(&self) -> Option {
queue: Mutex InorderQueue {
pub fn new() -> InorderQueue {
InorderQueue {
queue: Mutex::new(ArrayDeque::new()),
}
}
/// Add a new job to the in-order queue
///
/// # Arguments
///
/// - `job`: The job added to the back of the queue
///
/// # Returns
///
/// True if the element was added,
/// false to indicate that the queue is full.
pub fn send(&self, job: Job ) -> bool {
self.queue.lock().push_back(job).is_ok()
}
/// Consume completed jobs from the in-order queue
///
/// # Arguments
///
/// - `f`: function to apply to the body of each jobof each job.
/// - `limit`: maximum number of jobs to handle before returning
///
/// # Returns
///
/// A boolean indicating if the limit was reached:
/// true indicating that the limit was reached,
/// while false implies that the queue is empty or an uncompleted job was reached.
#[inline(always)]
pub fn handle ,
>(
device: D,
queue: Q,
receiver: Receiver