Re: Add msleep_interruptible() function to kernel/timer.c

From: Alan Cox
Date: Sun Aug 15 2004 - 07:58:55 EST


On Sul, 2004-08-15 at 13:18, maximilian attems wrote:
> + * msleep_interruptible - sleep waiting for waitqueue interruptions
> + * @msecs: Time in milliseconds to sleep for
> + */
> +void msleep_interruptible(unsigned int msecs)
> +{
> + unsigned long timeout = msecs_to_jiffies(msecs);
> +
> + while (timeout) {

You want to have while(timeout && !signal_pending(current))

A signal will wake the timeout which will then loop. It might also
be good to add

> + set_current_state(TASK_INTERRUPTIBLE);
> + timeout = schedule_timeout(timeout);
> + }

return timeout;

so that the caller knows more about how long the timer ran for before
the interrupt and if it was interrupted.


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