summaryrefslogtreecommitdiffstats
path: root/sys/compat/linuxkpi/common/include/linux/wait.h
diff options
context:
space:
mode:
Diffstat (limited to 'sys/compat/linuxkpi/common/include/linux/wait.h')
-rw-r--r--sys/compat/linuxkpi/common/include/linux/wait.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/sys/compat/linuxkpi/common/include/linux/wait.h b/sys/compat/linuxkpi/common/include/linux/wait.h
index c62f735..8afea08 100644
--- a/sys/compat/linuxkpi/common/include/linux/wait.h
+++ b/sys/compat/linuxkpi/common/include/linux/wait.h
@@ -34,6 +34,7 @@
#include <linux/spinlock.h>
#include <linux/sched.h>
#include <linux/list.h>
+#include <linux/jiffies.h>
#include <sys/param.h>
#include <sys/systm.h>
@@ -113,6 +114,52 @@ do { \
-_error; \
})
+#define wait_event_interruptible_timeout(q, cond, timeout) \
+({ \
+ void *c = &(q).wchan; \
+ long end = jiffies + timeout; \
+ int __ret = 0; \
+ int __rc = 0; \
+ \
+ if (!(cond)) { \
+ for (; __rc == 0;) { \
+ sleepq_lock(c); \
+ if (cond) { \
+ sleepq_release(c); \
+ __ret = 1; \
+ break; \
+ } \
+ sleepq_add(c, NULL, "completion", \
+ SLEEPQ_SLEEP | SLEEPQ_INTERRUPTIBLE, 0); \
+ sleepq_set_timeout(c, linux_timer_jiffies_until(end));\
+ __rc = sleepq_timedwait_sig (c, 0); \
+ if (__rc != 0) { \
+ /* check for timeout or signal. \
+ * 0 if the condition evaluated to false\
+ * after the timeout elapsed, 1 if the \
+ * condition evaluated to true after the\
+ * timeout elapsed. \
+ */ \
+ if (__rc == EWOULDBLOCK) \
+ __ret = (cond); \
+ else \
+ __ret = -ERESTARTSYS; \
+ } \
+ \
+ } \
+ } else { \
+ /* return remaining jiffies (at least 1) if the \
+ * condition evaluated to true before the timeout \
+ * elapsed. \
+ */ \
+ __ret = (end - jiffies); \
+ if( __ret < 1 ) \
+ __ret = 1; \
+ } \
+ __ret; \
+})
+
+
static inline int
waitqueue_active(wait_queue_head_t *q)
{
OpenPOWER on IntegriCloud