diff options
author | Kent Overstreet <koverstreet@google.com> | 2012-12-20 22:40:43 -0800 |
---|---|---|
committer | Kent Overstreet <koverstreet@google.com> | 2012-12-20 23:17:31 -0800 |
commit | f8bc2a7fd7bccb9dbd816a8310d6cf566c702a45 (patch) | |
tree | 58288ccea0857c5baf8000f772e8766f2950c3c2 | |
parent | 29594404d7fe73cd80eaa4ee8c43dcc53970c60e (diff) |
wait_event_interruptible_hrtimeout()
-rw-r--r-- | include/linux/wait.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index 168dfe122dd3..c2920d50afa4 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h @@ -330,6 +330,61 @@ do { \ __ret; \ }) +#define __wait_event_hrtimeout(wq, condition, timeout, state) \ +({ \ + int __ret = 0; \ + DEFINE_WAIT(__wait); \ + struct hrtimer_sleeper __t; \ + \ + hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \ + HRTIMER_MODE_REL); \ + hrtimer_init_sleeper(&__t, current); \ + if ((timeout).tv64 != KTIME_MAX) \ + hrtimer_start_range_ns(&__t.timer, timeout, \ + current->timer_slack_ns, \ + HRTIMER_MODE_REL); \ + \ + for (;;) { \ + prepare_to_wait(&wq, &__wait, state); \ + if (condition) \ + break; \ + if (state == TASK_INTERRUPTIBLE && \ + signal_pending(current)) { \ + __ret = -ERESTARTSYS; \ + break; \ + } \ + if (!__t.task) { \ + __ret = -ETIME; \ + break; \ + } \ + schedule(); \ + } \ + \ + hrtimer_cancel(&__t.timer); \ + destroy_hrtimer_on_stack(&__t.timer); \ + finish_wait(&wq, &__wait); \ + __ret; \ +}) + +#define wait_event_hrtimeout(wq, condition, timeout) \ +({ \ + int __ret = 0; \ + if (!(condition)) \ + __ret = __wait_event_hrtimeout(wq, condition, timeout, \ + TASK_UNINTERRUPTIBLE); \ + __ret; \ +}) + +#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \ +({ \ + long __ret = 0; \ + if (!(condition)) \ + __ret = __wait_event_hrtimeout(wq, condition, timeout, \ + TASK_INTERRUPTIBLE); \ + __ret; \ +}) + + #define __wait_event_interruptible_exclusive(wq, condition, ret) \ do { \ DEFINE_WAIT(__wait); \ |