linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, 2.5.40] Add wait_event_timeout & change wait_event_interruptible_timeout ret val
@ 2002-10-02  9:52 Hanumanthu. H
  0 siblings, 0 replies; only message in thread
From: Hanumanthu. H @ 2002-10-02  9:52 UTC (permalink / raw)
  To: linux-kernel; +Cc: torvalds

Hi,

Nice to have wait_event_interruptible_timeout, but it would be
necessary to return -ETIME upon timeout expiration (we need this
behaviour please !!). The following patch makes trivial changes
to __wait_even_interruptible_timeout macro to behave as below:

	if timeout occurs return -ETIME
	if interrupted, return -ERESTARTSYS
	if condition becomes true within specified timeout
	then return the remaining timeout

It also adds wait_event_timeout macro (again, we require it)

Please apply

~Hanu


--- linux-2.5.40/include/linux/sched.h	Wed Oct  2 13:59:47 2002
+++ linux/include/linux/sched.h	Wed Oct  2 14:37:52 2002
@@ -697,6 +697,33 @@
 	__wait_event(wq, condition);					\
 } while (0)

+#define __wait_event_timeout(wq, condition, ret) 			\
+do {									\
+	wait_queue_t __wait;						\
+	init_waitqueue_entry(&__wait, current);				\
+									\
+	add_wait_queue(&wq, &__wait);					\
+	for (;;) {							\
+		set_current_state(TASK_UNINTERRUPTIBLE);		\
+		if (condition)						\
+			break;						\
+		if(ret = schedule_timeout(ret))				\
+			continue;					\
+		ret = -ETIME;						\
+		break;							\
+	}								\
+	current->state = TASK_RUNNING;					\
+	remove_wait_queue(&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 {									\
 	wait_queue_t __wait;						\
@@ -726,7 +753,7 @@
 	__ret;								\
 })

-#define __wait_event_interruptible_timeout(wq, condition, ret)		\
+#define __wait_event_interruptible_timeout(wq, condition, tout, ret)	\
 do {									\
 	wait_queue_t __wait;						\
 	init_waitqueue_entry(&__wait, current);				\
@@ -737,10 +764,10 @@
 		if (condition)						\
 			break;						\
 		if (!signal_pending(current)) {				\
-			ret = schedule_timeout(ret);			\
-			if (!ret)					\
-				break;					\
-			continue;					\
+			if(tout = schedule_timeout(tout))		\
+				continue;				\
+			ret = -ETIME;					\
+			break;						\
 		}							\
 		ret = -ERESTARTSYS;					\
 		break;							\
@@ -751,10 +778,10 @@

 #define wait_event_interruptible_timeout(wq, condition, timeout)	\
 ({									\
-	long __ret = timeout;						\
+	long __tout = timeout, __ret = 0;				\
 	if (!(condition))						\
-		__wait_event_interruptible_timeout(wq, condition, __ret); \
-	__ret;								\
+		__wait_event_interruptible_timeout(wq, condition, __tout, __ret); \
+	(__ret == 0) ? __tout : __ret;					\
 })

 /*


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2002-10-02  9:30 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-10-02  9:52 [PATCH, 2.5.40] Add wait_event_timeout & change wait_event_interruptible_timeout ret val Hanumanthu. H

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).