Struct work_steal_queue::LocalQueue
source · #[repr(C)]pub struct LocalQueue<'l, T> { /* private fields */ }Implementations§
source§impl<'l, T> LocalQueue<'l, T>
impl<'l, T> LocalQueue<'l, T>
pub fn is_empty(&self) -> bool
pub fn is_full(&self) -> bool
pub fn len(&self) -> usize
sourcepub fn push_back(&self, item: T)
pub fn push_back(&self, item: T)
If the queue is full, first push half to global, then push the item to global.
Examples
use work_steal_queue::WorkStealQueue;
let queue = WorkStealQueue::new(1, 2);
let local = queue.local_queue();
for i in 0..4 {
local.push_back(i);
}
assert_eq!(local.pop_front(), Some(3));
assert_eq!(local.pop_front(), Some(0));
assert_eq!(local.pop_front(), Some(1));
assert_eq!(local.pop_front(), Some(2));
assert_eq!(local.pop_front(), None);sourcepub fn pop_front(&self) -> Option<T>
pub fn pop_front(&self) -> Option<T>
If the queue is empty, first try steal from global, then try steal from siblings.
Examples
use work_steal_queue::WorkStealQueue;
let queue = WorkStealQueue::new(1, 32);
queue.push(1);
queue.push(2);
let local = queue.local_queue();
assert_eq!(local.pop_front(), Some(1));
assert_eq!(local.pop_front(), Some(2));
assert_eq!(local.pop_front(), None);Examples
use work_steal_queue::WorkStealQueue;
let queue = WorkStealQueue::new(2, 64);
let local0 = queue.local_queue();
local0.push_back(2);
local0.push_back(3);
let local1 = queue.local_queue();
local1.push_back(0);
local1.push_back(1);
for i in 0..4 {
assert_eq!(local1.pop_front(), Some(i));
}
assert_eq!(local0.pop_front(), None);
assert_eq!(local1.pop_front(), None);
assert_eq!(queue.pop(), None);