#[repr(C)]pub struct LocalQueue<'l, T: Debug> { /* private fields */ }
Expand description
The work stealing local queue, exclusive to thread.
Implementations§
Source§impl<'l, T: Debug> LocalQueue<'l, T>
impl<'l, T: Debug> LocalQueue<'l, T>
Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true
if the local queue is full.
§Examples
use open_coroutine_queue::WorkStealQueue;
let queue = WorkStealQueue::new(1, 2);
let local = queue.local_queue();
assert!(local.is_empty());
for i in 0..2 {
local.push_back(i);
}
assert!(local.is_full());
assert_eq!(local.pop_front(), Some(0));
assert_eq!(local.len(), 1);
assert_eq!(local.pop_front(), Some(1));
assert_eq!(local.pop_front(), None);
assert!(local.is_empty());
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 open_coroutine_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(1));
assert_eq!(local.pop_front(), Some(3));
assert_eq!(local.pop_front(), Some(0));
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 open_coroutine_queue::WorkStealQueue;
let queue = WorkStealQueue::new(1, 32);
for i in 0..4 {
queue.push(i);
}
let local = queue.local_queue();
for i in 0..4 {
assert_eq!(local.pop_front(), Some(i));
}
assert_eq!(local.pop_front(), None);
assert_eq!(queue.pop(), None);
§Examples
use open_coroutine_queue::WorkStealQueue;
let queue = WorkStealQueue::new(2, 64);
let local0 = queue.local_queue();
local0.push_back(2);
local0.push_back(3);
local0.push_back(4);
local0.push_back(5);
let local1 = queue.local_queue();
local1.push_back(0);
local1.push_back(1);
for i in 0..6 {
assert_eq!(local1.pop_front(), Some(i));
}
assert_eq!(local0.pop_front(), None);
assert_eq!(local1.pop_front(), None);
assert_eq!(queue.pop(), None);
Trait Implementations§
Source§impl<T: Debug> Default for LocalQueue<'_, T>
impl<T: Debug> Default for LocalQueue<'_, T>
Auto Trait Implementations§
impl<'l, T> !Freeze for LocalQueue<'l, T>
impl<'l, T> !RefUnwindSafe for LocalQueue<'l, T>
impl<'l, T> !Send for LocalQueue<'l, T>
impl<'l, T> !Sync for LocalQueue<'l, T>
impl<'l, T> Unpin for LocalQueue<'l, T>
impl<'l, T> !UnwindSafe for LocalQueue<'l, T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more