diff options
Diffstat (limited to 'include/linux/wait.h')
-rw-r--r-- | include/linux/wait.h | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/include/linux/wait.h b/include/linux/wait.h index 7cb64d4b499d..ac38be2692d8 100644 --- a/include/linux/wait.h +++ b/include/linux/wait.h | |||
@@ -330,6 +330,92 @@ do { \ | |||
330 | __ret; \ | 330 | __ret; \ |
331 | }) | 331 | }) |
332 | 332 | ||
333 | #define __wait_event_hrtimeout(wq, condition, timeout, state) \ | ||
334 | ({ \ | ||
335 | int __ret = 0; \ | ||
336 | DEFINE_WAIT(__wait); \ | ||
337 | struct hrtimer_sleeper __t; \ | ||
338 | \ | ||
339 | hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \ | ||
340 | HRTIMER_MODE_REL); \ | ||
341 | hrtimer_init_sleeper(&__t, current); \ | ||
342 | if ((timeout).tv64 != KTIME_MAX) \ | ||
343 | hrtimer_start_range_ns(&__t.timer, timeout, \ | ||
344 | current->timer_slack_ns, \ | ||
345 | HRTIMER_MODE_REL); \ | ||
346 | \ | ||
347 | for (;;) { \ | ||
348 | prepare_to_wait(&wq, &__wait, state); \ | ||
349 | if (condition) \ | ||
350 | break; \ | ||
351 | if (state == TASK_INTERRUPTIBLE && \ | ||
352 | signal_pending(current)) { \ | ||
353 | __ret = -ERESTARTSYS; \ | ||
354 | break; \ | ||
355 | } \ | ||
356 | if (!__t.task) { \ | ||
357 | __ret = -ETIME; \ | ||
358 | break; \ | ||
359 | } \ | ||
360 | schedule(); \ | ||
361 | } \ | ||
362 | \ | ||
363 | hrtimer_cancel(&__t.timer); \ | ||
364 | destroy_hrtimer_on_stack(&__t.timer); \ | ||
365 | finish_wait(&wq, &__wait); \ | ||
366 | __ret; \ | ||
367 | }) | ||
368 | |||
369 | /** | ||
370 | * wait_event_hrtimeout - sleep until a condition gets true or a timeout elapses | ||
371 | * @wq: the waitqueue to wait on | ||
372 | * @condition: a C expression for the event to wait for | ||
373 | * @timeout: timeout, as a ktime_t | ||
374 | * | ||
375 | * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the | ||
376 | * @condition evaluates to true or a signal is received. | ||
377 | * The @condition is checked each time the waitqueue @wq is woken up. | ||
378 | * | ||
379 | * wake_up() has to be called after changing any variable that could | ||
380 | * change the result of the wait condition. | ||
381 | * | ||
382 | * The function returns 0 if @condition became true, or -ETIME if the timeout | ||
383 | * elapsed. | ||
384 | */ | ||
385 | #define wait_event_hrtimeout(wq, condition, timeout) \ | ||
386 | ({ \ | ||
387 | int __ret = 0; \ | ||
388 | if (!(condition)) \ | ||
389 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ | ||
390 | TASK_UNINTERRUPTIBLE); \ | ||
391 | __ret; \ | ||
392 | }) | ||
393 | |||
394 | /** | ||
395 | * wait_event_interruptible_hrtimeout - sleep until a condition gets true or a timeout elapses | ||
396 | * @wq: the waitqueue to wait on | ||
397 | * @condition: a C expression for the event to wait for | ||
398 | * @timeout: timeout, as a ktime_t | ||
399 | * | ||
400 | * The process is put to sleep (TASK_INTERRUPTIBLE) until the | ||
401 | * @condition evaluates to true or a signal is received. | ||
402 | * The @condition is checked each time the waitqueue @wq is woken up. | ||
403 | * | ||
404 | * wake_up() has to be called after changing any variable that could | ||
405 | * change the result of the wait condition. | ||
406 | * | ||
407 | * The function returns 0 if @condition became true, -ERESTARTSYS if it was | ||
408 | * interrupted by a signal, or -ETIME if the timeout elapsed. | ||
409 | */ | ||
410 | #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \ | ||
411 | ({ \ | ||
412 | long __ret = 0; \ | ||
413 | if (!(condition)) \ | ||
414 | __ret = __wait_event_hrtimeout(wq, condition, timeout, \ | ||
415 | TASK_INTERRUPTIBLE); \ | ||
416 | __ret; \ | ||
417 | }) | ||
418 | |||
333 | #define __wait_event_interruptible_exclusive(wq, condition, ret) \ | 419 | #define __wait_event_interruptible_exclusive(wq, condition, ret) \ |
334 | do { \ | 420 | do { \ |
335 | DEFINE_WAIT(__wait); \ | 421 | DEFINE_WAIT(__wait); \ |