vserver 1.9.3
[linux-2.6.git] / include / linux / wait.h
index 52edb17..21cd4df 100644 (file)
@@ -3,11 +3,20 @@
 
 #define WNOHANG                0x00000001
 #define WUNTRACED      0x00000002
+#define WSTOPPED       WUNTRACED
+#define WEXITED                0x00000004
+#define WCONTINUED     0x00000008
+#define WNOWAIT                0x01000000      /* Don't reap, just poll status.  */
 
 #define __WNOTHREAD    0x20000000      /* Don't wait on children of other threads in this group */
 #define __WALL         0x40000000      /* Wait on all children, regardless of type */
 #define __WCLONE       0x80000000      /* Wait only on non-SIGCHLD children */
 
+/* First argument to waitid: */
+#define P_ALL          0
+#define P_PID          1
+#define P_PGID         2
+
 #ifdef __KERNEL__
 
 #include <linux/config.h>
@@ -80,6 +89,15 @@ static inline int waitqueue_active(wait_queue_head_t *q)
        return !list_empty(&q->task_list);
 }
 
+/*
+ * Used to distinguish between sync and async io wait context:
+ * sync i/o typically specifies a NULL wait queue entry or a wait
+ * queue entry bound to a task (current task) to wake up.
+ * aio specifies a wait queue entry with an async notification
+ * callback routine, not associated with any task.
+ */
+#define is_sync_wait(wait)     (!(wait) || ((wait)->task))
+
 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
@@ -120,18 +138,15 @@ extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int
 
 #define __wait_event(wq, condition)                                    \
 do {                                                                   \
-       wait_queue_t __wait;                                            \
-       init_waitqueue_entry(&__wait, current);                         \
+       DEFINE_WAIT(__wait);                                            \
                                                                        \
-       add_wait_queue(&wq, &__wait);                                   \
        for (;;) {                                                      \
-               set_current_state(TASK_UNINTERRUPTIBLE);                \
+               prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);    \
                if (condition)                                          \
                        break;                                          \
                schedule();                                             \
        }                                                               \
-       current->state = TASK_RUNNING;                                  \
-       remove_wait_queue(&wq, &__wait);                                \
+       finish_wait(&wq, &__wait);                                      \
 } while (0)
 
 #define wait_event(wq, condition)                                      \
@@ -141,14 +156,35 @@ do {                                                                      \
        __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 {                                                                   \
-       wait_queue_t __wait;                                            \
-       init_waitqueue_entry(&__wait, current);                         \
+       DEFINE_WAIT(__wait);                                            \
                                                                        \
-       add_wait_queue(&wq, &__wait);                                   \
        for (;;) {                                                      \
-               set_current_state(TASK_INTERRUPTIBLE);                  \
+               prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);      \
                if (condition)                                          \
                        break;                                          \
                if (!signal_pending(current)) {                         \
@@ -158,8 +194,7 @@ do {                                                                        \
                ret = -ERESTARTSYS;                                     \
                break;                                                  \
        }                                                               \
-       current->state = TASK_RUNNING;                                  \
-       remove_wait_queue(&wq, &__wait);                                \
+       finish_wait(&wq, &__wait);                                      \
 } while (0)
 
 #define wait_event_interruptible(wq, condition)                                \
@@ -172,12 +207,10 @@ do {                                                                      \
 
 #define __wait_event_interruptible_timeout(wq, condition, ret)         \
 do {                                                                   \
-       wait_queue_t __wait;                                            \
-       init_waitqueue_entry(&__wait, current);                         \
+       DEFINE_WAIT(__wait);                                            \
                                                                        \
-       add_wait_queue(&wq, &__wait);                                   \
        for (;;) {                                                      \
-               set_current_state(TASK_INTERRUPTIBLE);                  \
+               prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);      \
                if (condition)                                          \
                        break;                                          \
                if (!signal_pending(current)) {                         \
@@ -189,8 +222,7 @@ do {                                                                        \
                ret = -ERESTARTSYS;                                     \
                break;                                                  \
        }                                                               \
-       current->state = TASK_RUNNING;                                  \
-       remove_wait_queue(&wq, &__wait);                                \
+       finish_wait(&wq, &__wait);                                      \
 } while (0)
 
 #define wait_event_interruptible_timeout(wq, condition, timeout)       \
@@ -200,7 +232,34 @@ do {                                                                       \
                __wait_event_interruptible_timeout(wq, condition, __ret); \
        __ret;                                                          \
 })
-       
+
+#define __wait_event_interruptible_exclusive(wq, condition, ret)       \
+do {                                                                   \
+       DEFINE_WAIT(__wait);                                            \
+                                                                       \
+       for (;;) {                                                      \
+               prepare_to_wait_exclusive(&wq, &__wait,                 \
+                                       TASK_INTERRUPTIBLE);            \
+               if (condition)                                          \
+                       break;                                          \
+               if (!signal_pending(current)) {                         \
+                       schedule();                                     \
+                       continue;                                       \
+               }                                                       \
+               ret = -ERESTARTSYS;                                     \
+               break;                                                  \
+       }                                                               \
+       finish_wait(&wq, &__wait);                                      \
+} while (0)
+
+#define wait_event_interruptible_exclusive(wq, condition)              \
+({                                                                     \
+       int __ret = 0;                                                  \
+       if (!(condition))                                               \
+               __wait_event_interruptible_exclusive(wq, condition, __ret);\
+       __ret;                                                          \
+})
+
 /*
  * Must be called with the spinlock in the wait_queue_head_t held.
  */