pub struct Bounded<T> {
head: CachePadded<AtomicUsize>,
tail: CachePadded<AtomicUsize>,
buffer: Box<[Slot<T>]>,
one_lap: usize,
mark_bit: usize,
}
Expand description
A bounded queue.
Fields§
§head: CachePadded<AtomicUsize>
The head of the queue.
This value is a “stamp” consisting of an index into the buffer, a mark bit, and a lap, but
packed into a single usize
. The lower bits represent the index, while the upper bits
represent the lap. The mark bit in the head is always zero.
Values are popped from the head of the queue.
tail: CachePadded<AtomicUsize>
The tail of the queue.
This value is a “stamp” consisting of an index into the buffer, a mark bit, and a lap, but
packed into a single usize
. The lower bits represent the index, while the upper bits
represent the lap. The mark bit indicates that the queue is closed.
Values are pushed into the tail of the queue.
buffer: Box<[Slot<T>]>
The buffer holding slots.
one_lap: usize
A stamp with the value of { lap: 1, mark: 0, index: 0 }
.
mark_bit: usize
If this bit is set in the tail, that means the queue is closed.
Implementations§
Source§impl<T> Bounded<T>
impl<T> Bounded<T>
Sourcepub fn push(&self, value: T) -> Result<(), PushError<T>>
pub fn push(&self, value: T) -> Result<(), PushError<T>>
Attempts to push an item into the queue.
Sourcepub fn force_push(&self, value: T) -> Result<Option<T>, ForcePushError<T>>
pub fn force_push(&self, value: T) -> Result<Option<T>, ForcePushError<T>>
Pushes an item into the queue, displacing another item if needed.
Sourcefn push_or_else<F>(&self, value: T, fail: F) -> Result<(), PushError<T>>
fn push_or_else<F>(&self, value: T, fail: F) -> Result<(), PushError<T>>
Attempts to push an item into the queue, running a closure on failure.
fail
is run when there is no more room left in the tail of the queue. The parameters of
this function are as follows:
- The item that failed to push.
- The value of
self.tail
before the new value would be inserted. - The value of
self.tail
after the new value would be inserted. - The slot that we attempted to push into.
If fail
returns Ok(val)
, we will try pushing val
to the head of the queue. Otherwise,
this function will return the error.