diff mbox

[RFC] time: add wait_interruptible_timeout macro to sleep (w. timeout) until wake_up

Message ID b170af451002260238p29c7db97nd50154bf7288ef42@mail.gmail.com (mailing list archive)
State Not Applicable
Headers show

Commit Message

Rafał Miłecki Feb. 26, 2010, 10:38 a.m. UTC
None
diff mbox

Patch

diff --git a/include/linux/wait.h b/include/linux/wait.h
index a48e16b..998475b 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -332,6 +332,31 @@  do {
                         \
       __ret;                                                          \
 })

+/**
+ * wait_interruptible_timeout - sleep until a waitqueue is woken up
+ * @wq: the waitqueue to wait on
+ * @timeout: timeout, in jiffies
+ *
+ * The process is put to sleep (TASK_INTERRUPTIBLE) until the waitqueue
+ * @wq is woken up. It can be done manually with wake_up or will happen
+ * if timeout elapses.
+ *
+ * The function returns 0 if the @timeout elapsed, remaining jiffies
+ * if workqueue was waken up earlier.
+ */
+#define wait_interruptible_timeout(wq, timeout)
         \
+({                                                                     \
+       long __ret = timeout;                                           \
+                                                                       \
+       DEFINE_WAIT(__wait);                                            \
+       prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE);              \
+       if (!signal_pending(current))                                   \
+               __ret = schedule_timeout(__ret);                        \
+       finish_wait(&wq, &__wait);                                      \
+                                                                       \
+       __ret;                                                          \
+})
+
 #define __wait_event_interruptible_exclusive(wq, condition, ret)       \