The core function of the function wake_up () that wakes up the waiting process in the waiting queue is the _ wake_up_common () function.
_ Wake_up_common (wait_queue_head_t * q, int mode,
Int nr_exclusive, int wake_flags, void * key)
Parameter introduction:
Q: Is the waiting queue header;
Mode: indicates the State mode of the process.
The value is task_interruptible and task_uniterruptible.
Nr_exclusive: Number exclusive;
Wake_flags: whether to synchronously wake up sync or asynchronously wake up async;
Key: generally null;
Static void _ wake_up_common (wait_queue_head_t * q, int mode,
Int nr_exclusive, int wake_flags, void * key)
{
Wait_queue_t * curr, * next;
List_for_each_entry_safe (curr, next, & Q-> task_list, task_list)
{
Unsigned int flags = curr-> flags;
If (curr-> func (curr, mode, wake_flags, key )&&
(Flags & wq_flag_exclusive )&&! -- Nr_exclusive)
Break;
}
}
Interpret the _ wake_up_common () function:
The list_for_each_entry_safe () function is used to traverse data items in the waiting queue and store the address of the current wait_queue_t item in curr;
Curr-> func () is an implementation function used to wake up processes in the waiting queue;
Curr-> func = autoremove_wake_function () or default_wake_function
In fact, autoremove_wake_function () and default_wake_function () functions are essentially the same. They are ultimately calling the try_to_wake_up () function.
The try_to_wake_up () function removes a process from the waiting queue and puts it into the ready queue waiting for scheduling by the scheduler schedule.
Therefore, the function of curr-> func () is to move the process from the waiting queue to the ready queue to wake up the process.
The _ wake_up_common () function is used to wake up all the waiting processes, wake up only one process, or wake up N processes each time. This depends on the nr_exclusive Parameter
When nr_exclusive = 0, __wake_up_common () wakes up all the waiting processes each time.
When nr_exclusive = 1 and wait for the waiting process in the queue to wait for the wake-up process, _ wake_up_common () wakes up only one waiting process at a time.
When nr_exclusive = N, __wake_up_common () Wake up n wait processes or N-1 non-mutex wait processes and 1 mutex wait process each time;
Implementation of the _ wake_up () function:
Void _ wake_up (wait_queue_head_t * q, unsigned int mode,
Int nr_exclusive, void * key)
{
Unsigned int flags;
Spin_lock_irqsave (& P-> lock, flags );
_ Wake_up_common (Q, mode, nr_exclusive, 0, key );
Spin_unlock_irqstore (& P-> lock, flags );
}
Implementation of the wake_up () function:
# Define wake_up (WQ) _ wake_up (WQ, task_normal, 1, null)
# Define wake_up_nr (WQ, NR) _ wake_up (WQ, task_normal, NR, null)
# Define wake_up_all (WQ) _ wake_up (WQ, task_normal, 0, null)
# Define wake_up_interruptible (WQ )\
_ Wake_up (WQ, task_interruptible, 1, null)
# Define wake_up_interruptible_nr (WQ, NR )\
_ Wake_up (WQ, task_interruptible, NR, null)
# Define wake_up_interruptible_all (WQ )\
_ Wake_up (WQ, task_interruptible, 0, null)
Wake_up () function set