pub mod biglock_fifo;
pub mod crossbeam_worklist;
pub mod message_passing_fifo;
pub trait Worklist<T> {
type Channel: WorklistChannel<T>;
fn create_channel(&mut self) -> Self::Channel;
fn initial_len(&self) -> usize;
fn stop(&mut self);
}
pub trait WorklistChannel<T> {
fn push(&self, item: T);
fn push_to(&self, item: T, _worker_id: u32) {
self.push(item)
}
fn pop(&self) -> Option<T>;
fn local_len(&self) -> usize;
fn global_len(&self) -> usize;
fn close(self);
}
pub trait WorklistPush<T>: Sized {
fn push(&mut self, item: T);
fn push_to(&mut self, item: T, _worker_id: u32) {
self.push(item)
}
fn current_worker_id(&self) -> u32;
}
pub(crate) struct PushWrapper<'a, W> {
worklist_channel: &'a W,
worker_id: u32,
}
impl<'a, W> PushWrapper<'a, W> {
pub fn new(worklist_channel: &'a W, current_worker_id: u32) -> Self {
Self {
worklist_channel,
worker_id: current_worker_id,
}
}
}
impl<'a, W, T> WorklistPush<T> for PushWrapper<'a, W>
where
W: WorklistChannel<T>,
{
fn push(&mut self, item: T) {
self.worklist_channel.push(item)
}
fn push_to(&mut self, item: T, worker_id: u32) {
self.worklist_channel.push_to(item, worker_id)
}
fn current_worker_id(&self) -> u32 {
self.worker_id
}
}
pub(crate) struct PushFnWrapper<F> {
push_fn: F,
worker_id: u32,
}
impl<F> PushFnWrapper<F> {
pub fn new(push_fn: F, current_worker_id: u32) -> Self {
Self {
push_fn,
worker_id: current_worker_id,
}
}
}
impl<T, F> WorklistPush<T> for PushFnWrapper<F>
where
F: FnMut(T),
{
fn push(&mut self, item: T) {
(self.push_fn)(item)
}
fn current_worker_id(&self) -> u32 {
self.worker_id
}
}