Linux uses wake_up_interruptible () to wake up processes that are registered on the wait queue

Source: Internet
Author: User

http://blog.sina.com.cn/s/blog_4770ef020101h48l.html function: Wake up the process registered on the wait queue

prototypes: #include
void wake_up_interruptible (wait_queue_head_t *q);

Description :
Wake-Up Q Specifies the process that is registered on the wait queue. The function does not immediately awaken the process directly, but instead is converted by the scheduler to the operational state .

variables :
Q: Wait for the queue variable pointer.

There's a problem with learning to drive recently, why does wait_event_interruptible (button_waitq,ev_press) need a global variable to remember the interruption?
When a read operation is implemented in the drive, the
    1. Wait_event_interruptible (BUTTON_WAITQ, ev_press);
The following statement is used in the interrupt function to wake up:
    1. ev_press = 1; Indicates that the interrupt has occurred
    2. Wake_up_interruptible (&BUTTON_WAITQ); Waking the hibernation process
In this case, the interrupt can be read correctly. I tried to mask ev_press = 1 respectively, and wake_up_interruptible (&BUTTON_WAITQ), and the code found that the interrupt was not properly generated.

Find the material and read the source code.
  1. #define WAIT_EVENT_INTERRUPTIBLE (wq,condition) \
  2. ({                                                      \
  3. Int__ret = 0; \
  4. if (! ( condition)) \
  5. __wait_event_interruptible (Wq,condition, __ret);
  6. __ret; \
  7. })
  1. #define __wait_event_interruptible (Wq, Condition,ret) \
  2. do{\
  3. Define_wait (__wait); \
  4. \
  5. for (;;) {                                                        \
  6. Prepare_to_wait (&wq,&__wait,task_interruptible); \
  7. if (condition) \
  8. Break \
  9. if (!signal_pending (current)) {\
  10. Schedule (); \
  11. Continue \
  12. }                                                        \
  13. Ret=-erestartsys; \
  14. Break \
  15. }                                                                \
  16. Finish_wait (&wq,&__wait); \
  17. } while (0)
__wait_event_interruptible () first defines and initializes a wait_queue_t variable __wait, where the data is current and the __wait is enqueued.
in an infinite loop, __wait_event_interruptible () resets the process to an interruptible suspend state, repeatedly checks if the condition is set up, exits if it is not established, and then resumes hibernation if it is not, and when the condition is satisfied, the running state of the process is set to Run State (at this point, if the following function is not executedwake_up_interruptible,abovewait_event_interruptibleand will continue to hibernate .)And clears the __wait from the wait queue so that the process can schedule the run. If the process currently has an asynchronous signal (POSIX), the-erestartsys is returned.
    1. Wake-Up Q Specifies the process that is registered on the wait queue. The function does not immediately awaken the process directly, but instead is converted by the scheduler to the operational state.

Linux uses wake_up_interruptible () to wake up processes that are registered on the wait queue

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.