pub struct WaitQueue { /* private fields */ }
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
impl WaitQueue
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates an empty wait queue with space for at least capacity
elements.
sourcepub fn wait(&self)
pub fn wait(&self)
Blocks the current task and put it into the wait queue, until other task notifies it.
sourcepub fn wait_until<F>(&self, condition: F)
pub fn wait_until<F>(&self, condition: F)
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.
sourcepub fn wait_timeout(&self, dur: Duration) -> bool
Available on crate feature irq
only.
pub fn wait_timeout(&self, dur: Duration) -> bool
irq
only.Blocks the current task and put it into the wait queue, until other tasks notify it, or the given duration has elapsed.
sourcepub fn wait_timeout_until<F>(&self, dur: Duration, condition: F) -> bool
Available on crate feature irq
only.
pub fn wait_timeout_until<F>(&self, dur: Duration, condition: F) -> bool
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.
sourcepub fn notify_one(&self, resched: bool) -> bool
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.
sourcepub fn notify_all(&self, resched: bool)
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.
sourcepub fn notify_task(&self, resched: bool, task: &AxTaskRef) -> bool
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.