The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
wait_queue.c File Reference

Functions

void wait_queue_init (wait_queue_t *wq)
 initialize a wait queue to empty.
void wait_queue_sleep_locked (wait_queue_t *wq, bool interruptible)
 sleep on a queue: the common part of the block functions, for code that builds its own (the timed queues).
void wait_queue_block (wait_queue_t *wq)
 block the current process on this queue and yield the CPU.
void wait_queue_block_interruptible (wait_queue_t *wq)
 like wait_queue_block, but a signal for the process also wakes it.
void wait_queue_wait_word (wait_queue_t *wq, const volatile uint32_t *word, uint32_t seen)
 sleep on a queue while a counter has the value the caller saw, until a wake or a signal.
void wait_queue_block_locked (wait_queue_t *wq, spinlock_t *lock)
 block on this queue while holding a spinlock, releasing the lock for as long as the process sleeps and holding it again on return.
void wait_queue_block_locked_interruptible (wait_queue_t *wq, spinlock_t *lock)
 like wait_queue_block_locked, but a signal for the process also wakes it.
bool wait_queue_interrupt (process_t *proc)
 take a process out of the queue it sleeps on, if it sleeps interruptibly, and make it runnable (a signal arrived).
void wait_queue_wake_one (wait_queue_t *wq)
 wake the process at the head of the queue, if any.
void wait_queue_wake_all_locked (wait_queue_t *wq)
 wait_queue_wake_all() for a caller that holds sched_lock.
void wait_queue_wake_all (wait_queue_t *wq)
 wake every process on the queue.

Function Documentation

◆ wait_queue_init()

void wait_queue_init ( wait_queue_t * wq)

initialize a wait queue to empty.

Parameters
wqthe queue to initialize.

◆ wait_queue_sleep_locked()

void wait_queue_sleep_locked ( wait_queue_t * wq,
bool interruptible )

sleep on a queue: the common part of the block functions, for code that builds its own (the timed queues).

call it with sched_lock held and interrupts masked. an interruptible sleep with a signal pending returns at once. it returns with sched_lock held.

Parameters
wqthe queue to sleep on.
interruptibletrue if a signal wakes the process.

◆ wait_queue_block()

void wait_queue_block ( wait_queue_t * wq)

block the current process on this queue and yield the CPU.

the process is marked BLOCKED, removed from the scheduler, and appended to the queue. returns only once another context has woken it, at which point it is runnable again.

Parameters
wqthe queue to block on.

◆ wait_queue_block_interruptible()

void wait_queue_block_interruptible ( wait_queue_t * wq)

like wait_queue_block, but a signal for the process also wakes it.

the caller re-tests its condition and signal_pending() after the return.

Parameters
wqthe queue to block on.

◆ wait_queue_wait_word()

void wait_queue_wait_word ( wait_queue_t * wq,
const volatile uint32_t * word,
uint32_t seen )

sleep on a queue while a counter has the value the caller saw, until a wake or a signal.

a waker changes the counter, then wakes the queue: a change before the sleep is seen, a later one finds the process asleep. for a condition that no single lock guards (waitpid).

Parameters
wqthe queue to sleep on.
wordthe counter.
seenthe value the caller read before it tested its condition.

◆ wait_queue_block_locked()

void wait_queue_block_locked ( wait_queue_t * wq,
spinlock_t * lock )

block on this queue while holding a spinlock, releasing the lock for as long as the process sleeps and holding it again on return.

this is the check-then-sleep pattern: take the lock, test a condition, and if it is not met call this. the lock is held from the test until the process is on the queue, so a waker, which takes the lock to change the condition, cannot slip in between and be lost. callers re-test the condition in a loop after waking.

Parameters
wqthe queue to block on.
locka lock taken with spin_lock_irqsave() by the caller.

◆ wait_queue_block_locked_interruptible()

void wait_queue_block_locked_interruptible ( wait_queue_t * wq,
spinlock_t * lock )

like wait_queue_block_locked, but a signal for the process also wakes it.

the caller re-tests its condition and signal_pending() after the return.

Parameters
wqthe queue to block on.
locka lock taken with spin_lock_irqsave() by the caller.

◆ wait_queue_interrupt()

bool wait_queue_interrupt ( struct process * proc)

take a process out of the queue it sleeps on, if it sleeps interruptibly, and make it runnable (a signal arrived).

it takes sched_lock.

Parameters
procthe process.
Returns
true if it was asleep and is now woken.

◆ wait_queue_wake_one()

void wait_queue_wake_one ( wait_queue_t * wq)

wake the process at the head of the queue, if any.

the woken process is marked READY and handed back to the scheduler.

Parameters
wqthe queue to wake from.

◆ wait_queue_wake_all_locked()

void wait_queue_wake_all_locked ( wait_queue_t * wq)

wait_queue_wake_all() for a caller that holds sched_lock.

Parameters
wqthe queue to drain.

◆ wait_queue_wake_all()

void wait_queue_wake_all ( wait_queue_t * wq)

wake every process on the queue.

Parameters
wqthe queue to drain.