waitqueue_active(9)
π NAME π
okay so this is waitqueue_active(9), straight out of the Kernel API Manual, and itβs here to locklessly test for waiters on the queue. Thatβs the whole name vibe, bestie. β¨
β¨ SYNOPSIS β¨
int waitqueue_active (struct wait_queue_head *wq_head );
π¦ ARGUMENTS π¦
wq_headβ the waitqueue to test for waiters. Thatβs it, thatβs the argument. π«Ά
π DESCRIPTION π
It returns true if the wait list is not empty. Thatβs the behavior, no cap. π
β οΈ NOTE β οΈ
this function is lockless and requires care, incorrect usage _will_ lead to sporadic and non-obvious failure. π
Use either while holding wait_queue_head::lock or when used for wakeups with an extra smp_mb like:
CPU0 - waker CPU1 - waiter
for (;;) {
cond = true; prepare_to_wait(wq_head, wait, state);
smp_mb; // smp_mb from set_current_state
if (waitqueue_active(wq_head)) if (cond)
wake_up(wq_head); break;
schedule;
}
finish_wait(wq_head, wait);
Because without the explicit smp_mb it's possible for the waitqueue_active load to get hoisted over the cond store such that we'll observe an empty wait list while the waiter might not observe cond.
Also note that this 'optimization' trades a spin_lock for an smp_mb, which (when the lock is uncontended) are of roughly equal cost.
π SEE ALSO π
Kernel file ./include/linux/wait.h
wq_has_single_sleeper(9)wq_has_sleeper(9)wake_up_pollfree(9)wait_event(9)wait_event_freezable(9)wait_event_timeout(9)wait_event_cmd(9)wait_event_interruptible(9)wait_event_interruptible_timeout(9)wait_event_hrtimeout(9)wait_event_interruptible_hrtimeout(9)wait_event_idle(9)wait_event_idle_exclusive(9)wait_event_idle_timeout(9)wait_event_idle_exclusive_timeout(9)wait_event_interruptible_locked(9)wait_event_interruptible_locked_irq(9)wait_event_interruptible_exclusive_locked(9)wait_event_interruptible_exclusive_locked_irq(9)wait_event_killable(9)wait_event_state(9)wait_event_killable_timeout(9)wait_event_lock_irq_cmd(9)wait_event_lock_irq(9)wait_event_interruptible_lock_irq_cmd(9)wait_event_interruptible_lock_irq(9)wait_event_interruptible_lock_irq_timeout(9)
okay bestie, thatβs the whole page β source/version: ./include/linux, date: October 2026, page: waitqueue_active(9) β byeee, go check your wait list ππ
π¦ where this page comes from
- nixpkgs unstable: linux-manual 7.3.1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms