/*************************************************************/
Wait_queue: What kind of problem is solved?
The current process waits for an event to occur: If a condition is true
Set the current process to: interruptible or uninterruptible
The current process is added to the linked list of the wait_queue_head associated with this time through wait_queue;
When an event occurs, or when the condition is established: Find the process of sleep on the event by Wait_queue_head
and awaken it;
/*************************************************************/
Init_waitqueue_head (&epfile->wait);
static inline int waitqueue_active (wait_queue_head_t *q)
{
Return!list_empty (&q->task_list);
}
/*************************************************************/
Take a specific wait_queue in F_FS.C as an example: look at the interfaces used
The arguments for the action function are: wait_queue_head_t, not Wait_queue
F_FS.C (drivers\usb\gadget\function): ret = wait_event_interruptible (epfile->wait, (ep = Epfile->ep));
F_FS.C (drivers\usb\gadget\function): Init_waitqueue_head (&epfile->wait);
F_FS.C (drivers\usb\gadget\function): Waitqueue_active (&epfile->wait));
F_FS.C (drivers\usb\gadget\function): Wake_up (&epfile->wait);
/*************************************************************/
How to make the current process sleep?
/*************************************************************/
/
Wait_event_interruptible (epfile->wait, (ep = Epfile->ep));
/**
* Wait_event_interruptible-sleep until a condition gets true
* @wq: The waitqueue to wait on
* @condition: A C expression for the event to wait for
*
* The process is put to sleep (task_interruptible) until the
* @condition evaluates to TRUE or a signal is received.
* The @condition is checked each time the Waitqueue @wq are woken up.
*
* WAKE_UP () have to is called after changing any variable that could
* Change the result of the wait condition.
*
* The function would return-erestartsys if it is interrupted by a
* Signal and 0 if @condition evaluated to true.
*/
#define WAIT_EVENT_INTERRUPTIBLE (Wq, condition) \
({ \
int __ret = 0; \
Might_sleep (); \
if (! ( condition)) \
__ret = __wait_event_interruptible (Wq, condition); \
__ret; \
})
Spin_lock_irqsave (&q->lock, flags);
if (List_empty (&wait->task_list)) {//[says Wait_queue task_list is empty and not said Wait_queue_head]
if (Wait->flags & wq_flag_exclusive)
__add_wait_queue_tail (q, wait);
Else
__add_wait_queue (q, wait);
}
Set_current_state (state);
Spin_unlock_irqrestore (&q->lock, flags);
return 0;
}
F_FS.C (drivers\usb\gadget\function): Wake_up (&epfile->wait);
/*************************************************************/
How to wake up the sleep process?
F_FS.C (drivers\usb\gadget\function): Wake_up (&epfile->wait);
/*************************************************************/
#define WAKE_UP (x) __wake_up (x, Task_normal, 1, NULL)
void __wake_up (wait_queue_head_t *q, unsigned int mode,
int nr_exclusive, void *key)
{
unsigned long flags;
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.