Struct LocalQueue

Source
#[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>

Source

pub fn is_empty(&self) -> bool

Returns true if the local queue is empty.

Source

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());
Source

pub fn len(&self) -> usize

Returns the number of elements in the queue.

Source

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);
Source

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<'l, T: Debug + Debug> Debug for LocalQueue<'l, T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Debug> Default for LocalQueue<'_, T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: Debug> Drop for LocalQueue<'_, T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.