patch from Ian Abbott <abbotti@mev.co.uk>:
authorFrank Mori Hess <fmhess@speakeasy.net>
Wed, 9 Feb 2005 01:53:23 +0000 (01:53 +0000)
committerFrank Mori Hess <fmhess@speakeasy.net>
Wed, 9 Feb 2005 01:53:23 +0000 (01:53 +0000)
This patch adds compatibility code for the 'wait_event()' macro in
linux/sched.h for kernels prior to 2.2.3.  The actual implementation in
this patch has been taken from 2.2.14.

include/linux/sched.h

index 65631334ee6b0556b1280932e9a349daba98bdaa..82bd7223564d3169e9758e5c2685363cc0a64799 100644 (file)
 #define signal_pending(x)      (((x)->signal) & (~(x)->blocked))
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,3)
+#define __wait_event(wq, condition)                                    \
+do {                                                                   \
+       struct wait_queue __wait;                                       \
+                                                                       \
+       __wait.task = current;                                          \
+       add_wait_queue(&wq, &__wait);                                   \
+       for (;;) {                                                      \
+               current->state = TASK_UNINTERRUPTIBLE;                  \
+               mb();                                                   \
+               if (condition)                                          \
+                       break;                                          \
+               schedule();                                             \
+       }                                                               \
+       current->state = TASK_RUNNING;                                  \
+       remove_wait_queue(&wq, &__wait);                                \
+} while (0)
+
+#define wait_event(wq, condition)                                      \
+do {                                                                   \
+       if (condition)                                                  \
+               break;                                                  \
+       __wait_event(wq, condition);                                    \
+} while (0)
+
+#define __wait_event_interruptible(wq, condition, ret)                 \
+do {                                                                   \
+       struct wait_queue __wait;                                       \
+                                                                       \
+       __wait.task = current;                                          \
+       add_wait_queue(&wq, &__wait);                                   \
+       for (;;) {                                                      \
+               current->state = TASK_INTERRUPTIBLE;                    \
+               mb();                                                   \
+               if (condition)                                          \
+                       break;                                          \
+               if (!signal_pending(current)) {                         \
+                       schedule();                                     \
+                       continue;                                       \
+               }                                                       \
+               ret = -ERESTARTSYS;                                     \
+               break;                                                  \
+       }                                                               \
+       current->state = TASK_RUNNING;                                  \
+       remove_wait_queue(&wq, &__wait);                                \
+} while (0)
+       
+#define wait_event_interruptible(wq, condition)                                \
+({                                                                     \
+       int __ret = 0;                                                  \
+       if (!(condition))                                               \
+               __wait_event_interruptible(wq, condition, __ret);       \
+       __ret;                                                          \
+})
+#endif
+
 #include_next <linux/sched.h>
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,20)