Skip to content

Wait Queues

Purpose

Wait queues allow a driver to put a process to sleep until a condition becomes true.

Common APIs

init_waitqueue_head(&dev->wq);
wait_event_interruptible(dev->wq, condition);
wake_up_interruptible(&dev->wq);

Typical Read Path

ret = wait_event_interruptible(dev->wq, !queue_empty(dev));
if (ret)
    return ret;

Return Behavior

Situation Typical Result
Condition becomes true Continue read path
Interrupted by signal Return error, often -ERESTARTSYS
Non-blocking mode Do not wait; return -EAGAIN

Common Pitfalls

Warning

The wakeup function only wakes sleeping tasks. The waiting condition must still become true.

Warning

Always check the condition after wakeup.