aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/wait.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r--include/linux/wait.h102
1 files changed, 97 insertions, 5 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h
index 7cb64d4b499d..1133695eb067 100644
--- a/include/linux/wait.h
+++ b/include/linux/wait.h
@@ -217,6 +217,8 @@ do { \
217 if (!ret) \ 217 if (!ret) \
218 break; \ 218 break; \
219 } \ 219 } \
220 if (!ret && (condition)) \
221 ret = 1; \
220 finish_wait(&wq, &__wait); \ 222 finish_wait(&wq, &__wait); \
221} while (0) 223} while (0)
222 224
@@ -233,8 +235,9 @@ do { \
233 * wake_up() has to be called after changing any variable that could 235 * wake_up() has to be called after changing any variable that could
234 * change the result of the wait condition. 236 * change the result of the wait condition.
235 * 237 *
236 * The function returns 0 if the @timeout elapsed, and the remaining 238 * The function returns 0 if the @timeout elapsed, or the remaining
237 * jiffies if the condition evaluated to true before the timeout elapsed. 239 * jiffies (at least 1) if the @condition evaluated to %true before
240 * the @timeout elapsed.
238 */ 241 */
239#define wait_event_timeout(wq, condition, timeout) \ 242#define wait_event_timeout(wq, condition, timeout) \
240({ \ 243({ \
@@ -302,6 +305,8 @@ do { \
302 ret = -ERESTARTSYS; \ 305 ret = -ERESTARTSYS; \
303 break; \ 306 break; \
304 } \ 307 } \
308 if (!ret && (condition)) \
309 ret = 1; \
305 finish_wait(&wq, &__wait); \ 310 finish_wait(&wq, &__wait); \
306} while (0) 311} while (0)
307 312
@@ -318,9 +323,10 @@ do { \
318 * wake_up() has to be called after changing any variable that could 323 * wake_up() has to be called after changing any variable that could
319 * change the result of the wait condition. 324 * change the result of the wait condition.
320 * 325 *
321 * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it 326 * Returns:
322 * was interrupted by a signal, and the remaining jiffies otherwise 327 * 0 if the @timeout elapsed, -%ERESTARTSYS if it was interrupted by
323 * if the condition evaluated to true before the timeout elapsed. 328 * a signal, or the remaining jiffies (at least 1) if the @condition
329 * evaluated to %true before the @timeout elapsed.
324 */ 330 */
325#define wait_event_interruptible_timeout(wq, condition, timeout) \ 331#define wait_event_interruptible_timeout(wq, condition, timeout) \
326({ \ 332({ \
@@ -330,6 +336,92 @@ do { \
330 __ret; \ 336 __ret; \
331}) 337})
332 338
339#define __wait_event_hrtimeout(wq, condition, timeout, state) \
340({ \
341 int __ret = 0; \
342 DEFINE_WAIT(__wait); \
343 struct hrtimer_sleeper __t; \
344 \
345 hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \
346 HRTIMER_MODE_REL); \
347 hrtimer_init_sleeper(&__t, current); \
348 if ((timeout).tv64 != KTIME_MAX) \
349 hrtimer_start_range_ns(&__t.timer, timeout, \
350 current->timer_slack_ns, \
351 HRTIMER_MODE_REL); \
352 \
353 for (;;) { \
354 prepare_to_wait(&wq, &__wait, state); \
355 if (condition) \
356 break; \
357 if (state == TASK_INTERRUPTIBLE && \
358 signal_pending(current)) { \
359 __ret = -ERESTARTSYS; \
360 break; \
361 } \
362 if (!__t.task) { \
363 __ret = -ETIME; \
364 break; \
365 } \
366 schedule(); \
367 } \
368 \
369 hrtimer_cancel(&__t.timer); \
370 destroy_hrtimer_on_stack(&__t.timer); \
371 finish_wait(&wq, &__wait); \
372 __ret; \
373})
374
375/**
376 * wait_event_hrtimeout - sleep until a condition gets true or a timeout elapses
377 * @wq: the waitqueue to wait on
378 * @condition: a C expression for the event to wait for
379 * @timeout: timeout, as a ktime_t
380 *
381 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
382 * @condition evaluates to true or a signal is received.
383 * The @condition is checked each time the waitqueue @wq is woken up.
384 *
385 * wake_up() has to be called after changing any variable that could
386 * change the result of the wait condition.
387 *
388 * The function returns 0 if @condition became true, or -ETIME if the timeout
389 * elapsed.
390 */
391#define wait_event_hrtimeout(wq, condition, timeout) \
392({ \
393 int __ret = 0; \
394 if (!(condition)) \
395 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
396 TASK_UNINTERRUPTIBLE); \
397 __ret; \
398})
399
400/**
401 * wait_event_interruptible_hrtimeout - sleep until a condition gets true or a timeout elapses
402 * @wq: the waitqueue to wait on
403 * @condition: a C expression for the event to wait for
404 * @timeout: timeout, as a ktime_t
405 *
406 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
407 * @condition evaluates to true or a signal is received.
408 * The @condition is checked each time the waitqueue @wq is woken up.
409 *
410 * wake_up() has to be called after changing any variable that could
411 * change the result of the wait condition.
412 *
413 * The function returns 0 if @condition became true, -ERESTARTSYS if it was
414 * interrupted by a signal, or -ETIME if the timeout elapsed.
415 */
416#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
417({ \
418 long __ret = 0; \
419 if (!(condition)) \
420 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
421 TASK_INTERRUPTIBLE); \
422 __ret; \
423})
424
333#define __wait_event_interruptible_exclusive(wq, condition, ret) \ 425#define __wait_event_interruptible_exclusive(wq, condition, ret) \
334do { \ 426do { \
335 DEFINE_WAIT(__wait); \ 427 DEFINE_WAIT(__wait); \