Re: about sleeping again!!

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hello,

> I'd like to put to sleep or what ever a kernel module's function until a 
> user space app generate an event in another function in the module. I'd 
> like this function that have to sleep or what ever you say be reentrant.
> I've been trying to do this a whole month, so.... I need help or I'll 
> lose my job :-D

In what context this function runs? If in process, then it may never be
reentered with the same current (ie. in the same task - different pthread
thread has different current too). And it's the current that's inserted into
waitqueue. If it should run... well, you can only wait in process context
(kernel thread is a process context too).

There can be any number of processes sleeping on one wait queue. One (global)
waitqueue for given type of events should suffice. All the tasks waiting for
it will wake up, one of them handles it, the others go back to sleep.

To put a function to sleep, create a global wait queue head (via
DECLARE_WAIT_QUEUE_HEAD macro). Then the function that sleeps will simply use
the macro wait_event with &<this global wq head> as first arg and an expression
that yields true when the function should wake up as second argument.
Use wait_event_interruptible instead if you want to wake up on signal arrival
too.

In function, where events are recieved, you record the relevant data somewhere
so the waiters can test them and simply wake_up(&<the global wq head>).
That will wake them up all, those concernced (you must solve relevant SMP races
et. al.) will handle it, the others will return to sleep.

So far I can't see any problem. Maybe I missed your point.

--------------------------------------------------------------------------------
                  				- Jan Hudec `Bulb' <bulb@ucw.cz>
--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
IRC Channel:   irc.openprojects.net / #kernelnewbies
Web Page:      http://www.kernelnewbies.org/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux