Struct axtask::WaitQueue

source ·
pub struct WaitQueue { /* private fields */ }
Available on crate feature multitask only.
Expand description

A queue to store sleeping tasks.

Examples

use axtask::WaitQueue;
use core::sync::atomic::{AtomicU32, Ordering};

static VALUE: AtomicU32 = AtomicU32::new(0);
static WQ: WaitQueue = WaitQueue::new();

axtask::init_scheduler();
// spawn a new task that updates `VALUE` and notifies the main task
axtask::spawn(|| {
    assert_eq!(VALUE.load(Ordering::Relaxed), 0);
    VALUE.fetch_add(1, Ordering::Relaxed);
    WQ.notify_one(true); // wake up the main task
});

WQ.wait(); // block until `notify()` is called
assert_eq!(VALUE.load(Ordering::Relaxed), 1);

Implementations§

source§

impl WaitQueue

source

pub const fn new() -> Self

Creates an empty wait queue.

source

pub fn with_capacity(capacity: usize) -> Self

Creates an empty wait queue with space for at least capacity elements.

source

pub fn wait(&self)

Blocks the current task and put it into the wait queue, until other task notifies it.

source

pub fn wait_until<F>(&self, condition: F)
where F: Fn() -> bool,

Blocks the current task and put it into the wait queue, until the given condition becomes true.

Note that even other tasks notify this task, it will not wake up until the condition becomes true.

source

pub fn wait_timeout(&self, dur: Duration) -> bool

Available on crate feature irq only.

Blocks the current task and put it into the wait queue, until other tasks notify it, or the given duration has elapsed.

source

pub fn wait_timeout_until<F>(&self, dur: Duration, condition: F) -> bool
where F: Fn() -> bool,

Available on crate feature irq only.

Blocks the current task and put it into the wait queue, until the given condition becomes true, or the given duration has elapsed.

Note that even other tasks notify this task, it will not wake up until the above conditions are met.

source

pub fn notify_one(&self, resched: bool) -> bool

Wakes up one task in the wait queue, usually the first one.

If resched is true, the current task will be preempted when the preemption is enabled.

source

pub fn notify_all(&self, resched: bool)

Wakes all tasks in the wait queue.

If resched is true, the current task will be preempted when the preemption is enabled.

source

pub fn notify_task(&self, resched: bool, task: &AxTaskRef) -> bool

Wake up the given task in the wait queue.

If resched is true, the current task will be preempted when the preemption is enabled.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.