Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use wake_up_interruptible

Tags:

linux-kernel

I wonder how can I use wake_up_interruptible, if it returns void: http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/include/linux/wait.h#L161 (_wake_up function returns void). For example, down_interruptible function returns int: http://www.cs.fsu.edu/~baker/devices/lxr/http/source/linux/kernel/semaphore.c#L75 This allows to write such code, for example:

if ( down_interruptible(&dev->sem) )
    return -ERESTARTSYS;
// continue: down_interruptible succeeded

When I call wake_up_interruptible, and it is interrupted, how can I know this, if it returns void?

like image 618
Alex F Avatar asked Dec 09 '12 13:12

Alex F


People also ask

What is the purpose of sleep block in I o section?

Sleeping causes the process to suspend execution, freeing the processor for other uses. At some future time, when the event being waited for occurs, the process will be woken up and will continue with its job.

What is wait queue?

A wait queue is used to wait for someone to wake you up when a certain condition is true. They must be used carefully to ensure there is no race condition.


1 Answers

i suppose normal usage scenario would be, in one thread:

for (;;) {
   wait_event_interruptible(wait_queue, condition);
   /* Some processing */
}

and from some other thread:

if (something_happened)
   wake_up_interruptible(wait_queue);

which will result in one process from wait_queue which is in TASK_INTERRUPTIBLE state to be woken up and evalueate condition

see some more examples here, a bit dated bit gives an idea

like image 84
Raber Avatar answered Sep 24 '22 15:09

Raber