Try_to_wake_up (), default_wake_function (), autoremove_wake_function ()

Source: Internet
Author: User

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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.