]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - include/linux/wait.h
Merge remote-tracking branch 'tip/auto-latest'
[karo-tx-linux.git] / include / linux / wait.h
index a2726c7dd2442314fba89dae8305fc3fff9de505..7f8caa519128d6bc2432161f05c53eebaa548065 100644 (file)
@@ -187,27 +187,30 @@ wait_queue_head_t *bit_waitqueue(void *, int);
        __cond || !__ret;                                               \
 })
 
-#define ___wait_signal_pending(state)                                  \
-       ((state == TASK_INTERRUPTIBLE && signal_pending(current)) ||    \
-        (state == TASK_KILLABLE && fatal_signal_pending(current)))
+#define ___wait_is_interruptible(state)                                        \
+       (!__builtin_constant_p(state) ||                                \
+               state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE)  \
 
 #define ___wait_event(wq, condition, state, exclusive, ret, cmd)       \
 ({                                                                     \
        __label__ __out;                                                \
-       DEFINE_WAIT(__wait);                                            \
+       wait_queue_t __wait;                                            \
        long __ret = ret;                                               \
                                                                        \
+       INIT_LIST_HEAD(&__wait.task_list);                              \
+       if (exclusive)                                                  \
+               __wait.flags = WQ_FLAG_EXCLUSIVE;                       \
+       else                                                            \
+               __wait.flags = 0;                                       \
+                                                                       \
        for (;;) {                                                      \
-               if (exclusive)                                          \
-                       prepare_to_wait_exclusive(&wq, &__wait, state); \
-               else                                                    \
-                       prepare_to_wait(&wq, &__wait, state);           \
+               long __int = prepare_to_wait_event(&wq, &__wait, state);\
                                                                        \
                if (condition)                                          \
                        break;                                          \
                                                                        \
-               if (___wait_signal_pending(state)) {                    \
-                       __ret = -ERESTARTSYS;                           \
+               if (___wait_is_interruptible(state) && __int) {         \
+                       __ret = __int;                                  \
                        if (exclusive) {                                \
                                abort_exclusive_wait(&wq, &__wait,      \
                                                     state, NULL);      \
@@ -270,11 +273,47 @@ do {                                                                      \
 #define wait_event_timeout(wq, condition, timeout)                     \
 ({                                                                     \
        long __ret = timeout;                                           \
-       if (!(condition))                                               \
+       if (!___wait_cond_timeout(condition))                           \
                __ret = __wait_event_timeout(wq, condition, timeout);   \
        __ret;                                                          \
 })
 
+#define __wait_event_cmd(wq, condition, cmd1, cmd2)                    \
+do {                                                                   \
+       DEFINE_WAIT(__wait);                                            \
+                                                                       \
+       for (;;) {                                                      \
+               prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE);    \
+               if (condition)                                          \
+                       break;                                          \
+               cmd1;                                                   \
+               schedule();                                             \
+               cmd2;                                                   \
+       }                                                               \
+       finish_wait(&wq, &__wait);                                      \
+} while (0)
+
+/**
+ * wait_event_cmd - sleep until a condition gets true
+ * @wq: the waitqueue to wait on
+ * @condition: a C expression for the event to wait for
+ * cmd1: the command will be executed before sleep
+ * cmd2: the command will be executed after sleep
+ *
+ * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
+ * @condition evaluates to true. The @condition is checked each time
+ * the waitqueue @wq is woken up.
+ *
+ * wake_up() has to be called after changing any variable that could
+ * change the result of the wait condition.
+ */
+#define wait_event_cmd(wq, condition, cmd1, cmd2)                      \
+do {                                                                   \
+       if (condition)                                                  \
+               break;                                                  \
+       __wait_event_cmd(wq, condition, cmd1, cmd2);                    \
+} while (0)
+
 #define __wait_event_interruptible(wq, condition)                      \
        ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0,          \
                      schedule())
@@ -328,7 +367,7 @@ do {                                                                        \
 #define wait_event_interruptible_timeout(wq, condition, timeout)       \
 ({                                                                     \
        long __ret = timeout;                                           \
-       if (!(condition))                                               \
+       if (!___wait_cond_timeout(condition))                           \
                __ret = __wait_event_interruptible_timeout(wq,          \
                                                condition, timeout);    \
        __ret;                                                          \
@@ -769,7 +808,7 @@ do {                                                                        \
                                                  timeout)              \
 ({                                                                     \
        long __ret = timeout;                                           \
-       if (!(condition))                                               \
+       if (!___wait_cond_timeout(condition))                           \
                __ret = __wait_event_interruptible_lock_irq_timeout(    \
                                        wq, condition, lock, timeout);  \
        __ret;                                                          \
@@ -791,6 +830,7 @@ extern long interruptible_sleep_on_timeout(wait_queue_head_t *q, signed long tim
  */
 void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
 void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state);
+long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state);
 void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
 void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key);
 int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);