Info

#define _wait_event(wq, condition) \

prepare_to_wait(&wq, &_wait, TASK_UNINTERRUPTIBLE); \

if (condition) \

After setting up the wait queue element with define_wait, the macro produces an endless loop. The process is put to sleep on the wait queue using prepare_to_wait. Every time it is woken up, the kernel checks if the specified condition is fulfilled, and exits the endless loop if this is so. Otherwise, control is given to the scheduler, and the task is put to sleep again.

It is essential that both wait_event and_wait_event are implemented as macros — this allows for specifying conditions given by standard C expressions! Since C does not support any nifty features like higher-order functions, this behavior would be impossible (or at least very clumsy) to achieve using regular procedures.

When the condition if fulfilled, finish_wait sets the task state back to task_running and removes the entry from the wait queue list.18

In addition to wait_event, the kernel defines several other functions to place the current process in a wait queue. Their implementation is practically identical to that of sleep_on:

Continue reading here: Info

Was this article helpful?

0 0