Skip to contentSkip to conversation

Add wait_event_timeout()

PATCH Russell King 4 participants 6 messages Sep 25, 2004 Scheduler

lore
Share & tools
lore
#0 lore raw

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.

include/linux/wait.h renamed from include/linux/wait.h.orig +23 -0
@@ -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);						\
#1 lore raw
Quoted 2 lines · Russell King

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.

#2 lore raw
Quoted 2 lines · Jon Masters

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.

#3 lore raw
In reply to Jon Masters
Quoted 2 lines · Russell King
Quoted 2 lines

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

Quoted 2 lines · Jon Masters

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

#4 lore raw
Quoted 2 lines · William Lee Irwin III

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.

#5 lore raw
In reply to Jon Masters
Quoted 8 lines · Jon Masters
Quoted 2 lines · Russell King

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)

Signature · 4 lines
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