2004-09-25 09:14:27

by Russell King

[permalink] [raw]
Subject: Add wait_event_timeout()

There appears to be one case missing from the wait_event() family -
the uninterruptible timeout wait. The following patch adds this.

This wait is particularly useful when (eg) you wish to pass work off
to an interrupt handler to perform, but also want to know if the
hardware has decided to go gaga under you. You don't want to sit
around waiting for something that'll never happen - you want to go
and wack the gremlin which caused the failure and retry.

--- linux/include/linux/wait.h.orig 2004-09-21 13:07:07.000000000 +0100
+++ linux/include/linux/wait.h 2004-09-25 09:33:19.000000000 +0100
@@ -156,6 +156,29 @@
__wait_event(wq, condition); \
} while (0)

+#define __wait_event_timeout(wq, condition, ret) \
+do { \
+ DEFINE_WAIT(__wait); \
+ \
+ for (;;) { \
+ prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
+ if (condition) \
+ break; \
+ ret = schedule_timeout(ret); \
+ if (!ret) \
+ break; \
+ } \
+ finish_wait(&wq, &__wait); \
+} while (0)
+
+#define wait_event_timeout(wq, condition, timeout) \
+({ \
+ long __ret = timeout; \
+ if (!(condition)) \
+ __wait_event_timeout(wq, condition, __ret); \
+ __ret; \
+})
+
#define __wait_event_interruptible(wq, condition, ret) \
do { \
DEFINE_WAIT(__wait); \


2004-09-25 09:42:17

by Jon Masters

[permalink] [raw]
Subject: Re: Add wait_event_timeout()

On Sat, 25 Sep 2004 10:13:59 +0100, Russell King <[email protected]> wrote:

> There appears to be one case missing from the wait_event() family -
> the uninterruptible timeout wait. The following patch adds this.


Any reason it's called wait_event_timeout then rather than
wait_event_uninterruptible_timeout?

Jon.

2004-09-25 09:44:36

by Jon Masters

[permalink] [raw]
Subject: Re: Add wait_event_timeout()

On Sat, 25 Sep 2004 10:42:15 +0100, Jon Masters <[email protected]> wrote:

> Any reason it's called wait_event_timeout then rather than
> wait_event_uninterruptible_timeout?

Aside from that. I think this is pretty handy to have around - I've
got some very buggy hardware right now which benefits from the odd
hard kick in its soft-core behind.

Jon.

2004-09-25 09:44:59

by William Lee Irwin III

[permalink] [raw]
Subject: Re: Add wait_event_timeout()

On Sat, 25 Sep 2004 10:13:59 +0100, Russell King <[email protected]> wrote:
>> There appears to be one case missing from the wait_event() family -
>> the uninterruptible timeout wait. The following patch adds this.

On Sat, Sep 25, 2004 at 10:42:15AM +0100, Jon Masters wrote:
> Any reason it's called wait_event_timeout then rather than
> wait_event_uninterruptible_timeout?

Anything interruptible is explicitly tagged as such; the "default",
sadly enough, is uninterruptible.


-- wli

2004-09-25 09:52:47

by Jon Masters

[permalink] [raw]
Subject: Re: Add wait_event_timeout()

On Sat, 25 Sep 2004 02:44:45 -0700, William Lee Irwin III
<[email protected]> wrote:

> Anything interruptible is explicitly tagged as such; the "default",
> sadly enough, is uninterruptible.

Fair enough, if that's the reasoning, then ok (I've never given that
much thought). Oh well...

Jon.

2004-09-25 09:56:56

by Russell King

[permalink] [raw]
Subject: Re: Add wait_event_timeout()

On Sat, Sep 25, 2004 at 10:42:15AM +0100, Jon Masters wrote:
> On Sat, 25 Sep 2004 10:13:59 +0100, Russell King <[email protected]> wrote:
>
> > There appears to be one case missing from the wait_event() family -
> > the uninterruptible timeout wait. The following patch adds this.
>
>
> Any reason it's called wait_event_timeout then rather than
> wait_event_uninterruptible_timeout?

Because I chose to follow the existing naming scheme.

wait_event() - uninterruptible wait
wait_event_interruptible() - interruptible wait
wait_event_interruptible_timeout() - interruptible wait with timeout

so, the uninterruptible wait with timeout can only logically be:

wait_event_timeout()

Lets not go starting a new naming scheme. 8)

--
Russell King
Linux kernel 2.6 ARM Linux - http://www.arm.linux.org.uk/
maintainer of: 2.6 PCMCIA - http://pcmcia.arm.linux.org.uk/
2.6 Serial core