diff mbox

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

Message ID 1266761422-2921-1-git-send-email-zajec5@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Rafał Miłecki Feb. 21, 2010, 2:10 p.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)	\
 do {									\
 	DEFINE_WAIT(__wait);						\