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

Re: tsleep question



Alexandre Ratchov <aratchov@magphy.ujf-grenoble.fr> writes:

> Hello, 
> 
> i'm working on a midi device driver and i have the following question
> about the 'read' system call:
> 
> s = splaudio();
> while (!data) {
> 	tsleep(&bla, PWAIT|PCATCH, "rd", 0);
> }
> splx(s);
> 
> 
> the caller needs to sleep until data becomes available, when data arrives,
> the interrupt handler calls wakeup(). If i do not disable interrupts, an
> interrupt can occur between the "while" and the "tsleep", which will "hang"
> the process. When tsleep switches to another process context, does it
> restore the system priority level? Is this the right way to wait for data?

Yes, tsleep restores the spl level.
Yes, this is a very correct way to wait for data.

//art