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>

source

pub fn new(local_queues: usize, local_queue_size: u16) -> Self

Create a new work queue.

local_queues is the number of LocalQueues 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);
source

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.

source

pub fn local_queues(&self) -> LocalQueues<'_, T>

Iterate over the local queues of this queue.

Panics

This will panic if called more than one time.

source

pub fn searchers(&self) -> usize

Get the number of threads that are currently searching for work inside pop.

If this number is too high, you may wish to avoid calling pop to reduce contention.

Trait Implementations§

source§

impl<T> Clone for Queue<T>

source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Queue<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.