#[repr(transparent)]pub struct Stealer<T> { /* private fields */ }
Expand description
Handle for multi-threaded stealing operations.
Implementations§
source§impl<T> Stealer<T>
impl<T> Stealer<T>
sourcepub fn steal<C>(&self, dest: &Worker<T>, count_fn: C) -> Result<usize, StealError>where
C: FnMut(usize) -> usize,
pub fn steal<C>(&self, dest: &Worker<T>, count_fn: C) -> Result<usize, StealError>where
C: FnMut(usize) -> usize,
Attempts to steal items from the head of the queue and move them to the tail of another queue.
Up to N
items are moved to the destination queue, where N
is
specified by a closure which takes as argument the total count of items
available for stealing. Upon success, the number of items ultimately
transferred to the destination queue can be from 1 to N
, depending on
the number of available items and the capacity of the destination queue;
the count of transferred items is returned as the success payload.
Errors
An error is returned in the following cases:
- no item was stolen, either because the queue is empty, the
destination is full or
N
is 0, - a concurrent stealing operation is ongoing.
sourcepub fn steal_and_pop<C>(
&self,
dest: &Worker<T>,
count_fn: C
) -> Result<(T, usize), StealError>where
C: FnMut(usize) -> usize,
pub fn steal_and_pop<C>(
&self,
dest: &Worker<T>,
count_fn: C
) -> Result<(T, usize), StealError>where
C: FnMut(usize) -> usize,
Attempts to steal items from the head of the queue, returning one of them directly and moving the others to the tail of another queue.
Up to N
items are stolen (including the one returned directly), where
N
is specified by a closure which takes as argument the total count of
items available for stealing. Upon success, one item is returned and
from 0 to N-1
items are moved to the destination queue, depending on
the number of available items and the capacity of the destination queue;
the number of transferred items is returned as the second field of the
success value.
The returned item is the most recent one among the stolen items.
Errors
An error is returned in the following cases:
- no item was stolen, either because the queue is empty or
N
is 0, - a concurrent stealing operation is ongoing.
Failure to transfer any item to the destination queue is not considered
an error as long as one element could be returned directly. This can
occur if the destination queue is full, if the source queue has only one
item or if N
is 1.