[PATCH, 2.5.40] Add wait_event_timeout & change wait_event_interruptible_timeout ret val

From: Hanumanthu. H (hanumanthu.hanok@wipro.com)
Date: Wed Oct 02 2002 - 04:52:31 EST


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; \
 })

 /*

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



This archive was generated by hypermail 2b29 : Mon Oct 07 2002 - 22:00:33 EST