Struct utils_atomics::fill_queue::FillQueue
source · alloc
only.Implementations§
source§impl<T, A: Allocator> FillQueue<T, A>
impl<T, A: Allocator> FillQueue<T, A>
source§impl<T, A: Allocator> FillQueue<T, A>
impl<T, A: Allocator> FillQueue<T, A>
sourcepub fn try_push(&self, v: T) -> Result<(), AllocError>
pub fn try_push(&self, v: T) -> Result<(), AllocError>
Uses atomic operations to push an element to the queue.
Errors
This method returns an error if alloc
fails to allocate the memory needed for the node.
Example
use utils_atomics::prelude::*;
let queue = FillQueue::<i32>::new();
assert!(queue.try_push(1).is_ok());
assert_eq!(queue.chop().next(), Some(1));
sourcepub fn try_push_mut(&mut self, v: T) -> Result<(), AllocError>
pub fn try_push_mut(&mut self, v: T) -> Result<(), AllocError>
Uses non-atomic operations to push an element to the queue.
Safety
This method is safe because the mutable reference guarantees we are the only thread that can access this queue.
Errors
This method returns an error if alloc
fails to allocate the memory needed for the node.
Example
use utils_atomics::prelude::*;
let mut queue = FillQueue::<i32>::new();
assert!(queue.try_push_mut(1).is_ok());
assert_eq!(queue.chop_mut().next(), Some(1));
source§impl<T, A: Allocator> FillQueue<T, A>
impl<T, A: Allocator> FillQueue<T, A>
sourcepub fn chop(&self) -> ChopIter<T, A> ⓘwhere
A: Clone,
pub fn chop(&self) -> ChopIter<T, A> ⓘwhere
A: Clone,
Returns a LIFO (Last In First Out) iterator over a chopped chunk of a FillQueue
.
The elements that find themselves inside the chopped region of the queue will be accessed through non-atomic operations.
Example
use utils_atomics::prelude::*;
let queue = FillQueue::<i32>::new();
queue.push(1);
queue.push(2);
queue.push(3);
let mut iter = queue.chop();
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None)
sourcepub fn chop_mut(&mut self) -> ChopIter<T, A> ⓘwhere
A: Clone,
pub fn chop_mut(&mut self) -> ChopIter<T, A> ⓘwhere
A: Clone,
Returns a LIFO (Last In First Out) iterator over a chopped chunk of a FillQueue
. The chopping is done with non-atomic operations.
Safety
This method is safe because the mutable reference guarantees we are the only thread that can access this queue.
Example
use utils_atomics::prelude::*;
let mut queue = FillQueue::<i32>::new();
queue.push_mut(1);
queue.push_mut(2);
queue.push_mut(3);
let mut iter = queue.chop_mut();
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(1));
assert_eq!(iter.next(), None)