First, we will introduce a very basic function: try_to_wake_up ()
This function is used to wake up a process from the waiting queue and put it in the ready queue.
Static int try_to_wake_up (struct task_struct * P, int state,
Int wake_flags)
Parameter description: P: indicates the process to be awakened;
State: the Status mask of a wake-up process;
Wake_flags: synchronous or asynchronous wake-up;
Try_to_wake_up () returns a failure value if the p process is already active.
1 is returned for success; 0 is returned for failure;
Default wake-up function of the waiting process in the waiting queue: default_wake_function ()
Int default_wake_function (wait_queue_t * curr, unsigned int mode,
Int wake_flags, void * key)
{
Return try_to_wake_up (curr-> private, mode, wake_flags );
}
Export_symbol (default_wake_function );
It can be seen that default_wake_function () is essentially an encapsulation of the try_to_wake_up () function.
Int autoremove_wake_function (wait_queue_t * wait,
Unsigned int mode, int sync, void * key)
{
Int ret;
Ret = default_wake_function (wait, mode, sync, key); // waiting queue
Find the waiting process that meets the conditions;
If (RET)
List_del_init (& wait-> task_list); // The waiting process that meets the conditions starts from waiting
Deleted from the queue;
Return ret;
}
From the above functions, we can summarize the process of processing the process state in the Linux kernel:
When a running process needs to be blocked, call the set_curent_state () or _ set_current_state () function to change the state of a process, and assign a wait_queue_t struct through init_wait, then, hook the current process and add it to the waiting queue through the add_wait_queue () function or the add_wait_queue_exclusive () function.
Try_to_wake_up (), default_wake_function (), autoremove_wake_function ()