For a class project involving scheduling processes using blocking and locks, we're supposed to use two kernel functions:
int wait_event_interruptible(wait_queue_head_t q, CONDITION);
void wake_up_all(wait_queue_head_t *q);
The explanation of wait_event_interruptible is:
Blocks the current task on a wait queue until a CONDITION becomes true.
This is actually a macro. It repeatedly evaluates the CONDITION, which is a fragment of C code such as foo == bar or function() > 3. Once the condition is true, wait_event_interruptible returns 0. If the condition is false, the current task is added to the wait_queue_head_t list with state TASK_INTERRUPTIBLE; the current process will block until wake_up_all(&q) is called, then it will re-check the CONDITION. If the current task receives a signal before CONDITION becomes true, the macro returns -ERESTARTSYS.
And the explanation of wake_up_all is:
Wake up all tasks in the wait queue by setting their states to TASK_RUNNABLE.
I'm having a hard time figuring out how exactly these functions work and how to use them together. For example, when does the CONDITION get checked? Does wait_event_interruptible continuously poll, or does it only recheck the condition when wake_up_all is called? This explanation is a little unclear.
If you could give an example of how to use these functions together that would be very helpful.