Re: sleep_on, wake_up question

Manfred Spraul (manfreds@colorfullife.com)
Thu, 30 Dec 1999 20:26:16 +0100


"Richard B. Johnson" wrote:
>
> Mark,
> I checked a later kernel and it can get stuck. However, you can
> use sleep_on_timeout() to make sure you do get awakened.

Ha? Do you really suggest adding a timeout to recover from the lock-up?
You should _remove_ the lock-up instead of hiding it.

Just copy the code from interruptible_sleep_on(), and add
spin_unlock_irq()/spin_lock_irq() around the schedule() call.

You must unlock _after_ you have set "current->state =
TASK_INTERRUPTIBLE", then the lock-up is gone.
[or you could set current->state before you can cause the interrupt, but
this is extremely dangerous on SMP - the cpu's could reorder the memory
accesses.]

spin_lock_irq(&device_lock);
play_with_the_hardware();

while(!command_finished) {
current->state = TASK_INTERRUPTIBLE;
spin_unlock_irq(&device_lock);
schedule();
spin_lock_irq(&device_lock);
if(signal_pending(current)) {
cancel_command();
goto out_unlock;
}
}
store_the_result_from_the_hardware();
out_unlock:
spin_unlock_irq(&device_lock);

isr()
{
spin_lock_irqsave(&device_lock,flags);
command_finished = 1;
wake_up_interruptible(&wait);
spin_unlock_irqrestore(&device_lock,flags);
}

--
	Manfred

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.tux.org/lkml/