Struct work_queue::Queue
source · pub struct Queue<T>(_);
Expand description
A work queue.
This implements Clone
and so multiple handles to the queue can be easily created and
shared.
Implementations§
source§impl<T> Queue<T>
impl<T> Queue<T>
sourcepub fn new(local_queues: usize, local_queue_size: u16) -> Self
pub fn new(local_queues: usize, local_queue_size: u16) -> Self
Create a new work queue.
local_queues
is the number of LocalQueue
s yielded by Self::local_queues
. Typically
you will have a local queue for each thread on a thread pool.
local_queue_size
is the number of items that can be stored in each local queue before it
overflows into the global one. You should fine-tune this to your needs.
Panics
This will panic if the local queue size is not a power of two.
Examples
use work_queue::Queue;
let threads = 4;
let queue: Queue<i32> = Queue::new(threads, 512);
sourcepub fn push(&self, item: T)
pub fn push(&self, item: T)
Push an item to the global queue. When one of the local queues empties, they can pick this item up.
sourcepub fn local_queues(&self) -> LocalQueues<'_, T> ⓘ
pub fn local_queues(&self) -> LocalQueues<'_, T> ⓘ
Trait Implementations§
Auto Trait Implementations§
impl<T> !RefUnwindSafe for Queue<T>
impl<T> Send for Queue<T>where T: Send,
impl<T> Sync for Queue<T>where T: Send,
impl<T> Unpin for Queue<T>
impl<T> !UnwindSafe for Queue<T>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more