5 #include <linux/list.h>
6 #include <linux/stddef.h>
7 #include <linux/spinlock.h>
8 #include <asm/current.h>
9 #include <uapi/linux/wait.h>
11 typedef struct __wait_queue wait_queue_t;
12 typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
13 int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
17 #define WQ_FLAG_EXCLUSIVE 0x01
19 wait_queue_func_t func;
20 struct list_head task_list;
28 struct wait_bit_queue {
29 struct wait_bit_key key;
33 struct __wait_queue_head {
35 struct list_head task_list;
37 typedef struct __wait_queue_head wait_queue_head_t;
42 * Macros for declaration and initialisaton of the datatypes
45 #define __WAITQUEUE_INITIALIZER(name, tsk) { \
47 .func = default_wake_function, \
48 .task_list = { NULL, NULL } }
50 #define DECLARE_WAITQUEUE(name, tsk) \
51 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
53 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
54 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
55 .task_list = { &(name).task_list, &(name).task_list } }
57 #define DECLARE_WAIT_QUEUE_HEAD(name) \
58 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
60 #define __WAIT_BIT_KEY_INITIALIZER(word, bit) \
61 { .flags = word, .bit_nr = bit, }
63 extern void __init_waitqueue_head(wait_queue_head_t *q, const char *name, struct lock_class_key *);
65 #define init_waitqueue_head(q) \
67 static struct lock_class_key __key; \
69 __init_waitqueue_head((q), #q, &__key); \
73 # define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
74 ({ init_waitqueue_head(&name); name; })
75 # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
76 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
78 # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
81 static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
85 q->func = default_wake_function;
88 static inline void init_waitqueue_func_entry(wait_queue_t *q,
89 wait_queue_func_t func)
96 static inline int waitqueue_active(wait_queue_head_t *q)
98 return !list_empty(&q->task_list);
101 extern void add_wait_queue(wait_queue_head_t *q, wait_queue_t *wait);
102 extern void add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait);
103 extern void remove_wait_queue(wait_queue_head_t *q, wait_queue_t *wait);
105 static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
107 list_add(&new->task_list, &head->task_list);
111 * Used for wake-one threads:
113 static inline void __add_wait_queue_exclusive(wait_queue_head_t *q,
116 wait->flags |= WQ_FLAG_EXCLUSIVE;
117 __add_wait_queue(q, wait);
120 static inline void __add_wait_queue_tail(wait_queue_head_t *head,
123 list_add_tail(&new->task_list, &head->task_list);
126 static inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q,
129 wait->flags |= WQ_FLAG_EXCLUSIVE;
130 __add_wait_queue_tail(q, wait);
133 static inline void __remove_wait_queue(wait_queue_head_t *head,
136 list_del(&old->task_list);
139 void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
140 void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key);
141 void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr,
143 void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr);
144 void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr);
145 void __wake_up_bit(wait_queue_head_t *, void *, int);
146 int __wait_on_bit(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned);
147 int __wait_on_bit_lock(wait_queue_head_t *, struct wait_bit_queue *, int (*)(void *), unsigned);
148 void wake_up_bit(void *, int);
149 int out_of_line_wait_on_bit(void *, int, int (*)(void *), unsigned);
150 int out_of_line_wait_on_bit_lock(void *, int, int (*)(void *), unsigned);
151 wait_queue_head_t *bit_waitqueue(void *, int);
153 #define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
154 #define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
155 #define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL)
156 #define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1)
157 #define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0)
159 #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
160 #define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
161 #define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
162 #define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
165 * Wakeup macros to be used to report events to the targets.
167 #define wake_up_poll(x, m) \
168 __wake_up(x, TASK_NORMAL, 1, (void *) (m))
169 #define wake_up_locked_poll(x, m) \
170 __wake_up_locked_key((x), TASK_NORMAL, (void *) (m))
171 #define wake_up_interruptible_poll(x, m) \
172 __wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m))
173 #define wake_up_interruptible_sync_poll(x, m) \
174 __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
176 #define __wait_event(wq, condition) \
178 DEFINE_WAIT(__wait); \
181 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
186 finish_wait(&wq, &__wait); \
190 * wait_event - sleep until a condition gets true
191 * @wq: the waitqueue to wait on
192 * @condition: a C expression for the event to wait for
194 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
195 * @condition evaluates to true. The @condition is checked each time
196 * the waitqueue @wq is woken up.
198 * wake_up() has to be called after changing any variable that could
199 * change the result of the wait condition.
201 #define wait_event(wq, condition) \
205 __wait_event(wq, condition); \
208 #define __wait_event_timeout(wq, condition, ret) \
210 DEFINE_WAIT(__wait); \
213 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
216 ret = schedule_timeout(ret); \
220 if (!ret && (condition)) \
222 finish_wait(&wq, &__wait); \
226 * wait_event_timeout - sleep until a condition gets true or a timeout elapses
227 * @wq: the waitqueue to wait on
228 * @condition: a C expression for the event to wait for
229 * @timeout: timeout, in jiffies
231 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
232 * @condition evaluates to true. The @condition is checked each time
233 * the waitqueue @wq is woken up.
235 * wake_up() has to be called after changing any variable that could
236 * change the result of the wait condition.
238 * The function returns 0 if the @timeout elapsed, or the remaining
239 * jiffies (at least 1) if the @condition evaluated to %true before
240 * the @timeout elapsed.
242 #define wait_event_timeout(wq, condition, timeout) \
244 long __ret = timeout; \
246 __wait_event_timeout(wq, condition, __ret); \
250 #define __wait_event_interruptible(wq, condition, ret) \
252 DEFINE_WAIT(__wait); \
255 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
258 if (!signal_pending(current)) { \
262 ret = -ERESTARTSYS; \
265 finish_wait(&wq, &__wait); \
269 * wait_event_interruptible - sleep until a condition gets true
270 * @wq: the waitqueue to wait on
271 * @condition: a C expression for the event to wait for
273 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
274 * @condition evaluates to true or a signal is received.
275 * The @condition is checked each time the waitqueue @wq is woken up.
277 * wake_up() has to be called after changing any variable that could
278 * change the result of the wait condition.
280 * The function will return -ERESTARTSYS if it was interrupted by a
281 * signal and 0 if @condition evaluated to true.
283 #define wait_event_interruptible(wq, condition) \
287 __wait_event_interruptible(wq, condition, __ret); \
291 #define __wait_event_interruptible_timeout(wq, condition, ret) \
293 DEFINE_WAIT(__wait); \
296 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
299 if (!signal_pending(current)) { \
300 ret = schedule_timeout(ret); \
305 ret = -ERESTARTSYS; \
308 if (!ret && (condition)) \
310 finish_wait(&wq, &__wait); \
314 * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
315 * @wq: the waitqueue to wait on
316 * @condition: a C expression for the event to wait for
317 * @timeout: timeout, in jiffies
319 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
320 * @condition evaluates to true or a signal is received.
321 * The @condition is checked each time the waitqueue @wq is woken up.
323 * wake_up() has to be called after changing any variable that could
324 * change the result of the wait condition.
327 * 0 if the @timeout elapsed, -%ERESTARTSYS if it was interrupted by
328 * a signal, or the remaining jiffies (at least 1) if the @condition
329 * evaluated to %true before the @timeout elapsed.
331 #define wait_event_interruptible_timeout(wq, condition, timeout) \
333 long __ret = timeout; \
335 __wait_event_interruptible_timeout(wq, condition, __ret); \
339 #define __wait_event_hrtimeout(wq, condition, timeout, state) \
342 DEFINE_WAIT(__wait); \
343 struct hrtimer_sleeper __t; \
345 hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \
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, \
354 prepare_to_wait(&wq, &__wait, state); \
357 if (state == TASK_INTERRUPTIBLE && \
358 signal_pending(current)) { \
359 __ret = -ERESTARTSYS; \
369 hrtimer_cancel(&__t.timer); \
370 destroy_hrtimer_on_stack(&__t.timer); \
371 finish_wait(&wq, &__wait); \
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
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.
385 * wake_up() has to be called after changing any variable that could
386 * change the result of the wait condition.
388 * The function returns 0 if @condition became true, or -ETIME if the timeout
391 #define wait_event_hrtimeout(wq, condition, timeout) \
395 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
396 TASK_UNINTERRUPTIBLE); \
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
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.
410 * wake_up() has to be called after changing any variable that could
411 * change the result of the wait condition.
413 * The function returns 0 if @condition became true, -ERESTARTSYS if it was
414 * interrupted by a signal, or -ETIME if the timeout elapsed.
416 #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
420 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
421 TASK_INTERRUPTIBLE); \
425 #define __wait_event_interruptible_exclusive(wq, condition, ret) \
427 DEFINE_WAIT(__wait); \
430 prepare_to_wait_exclusive(&wq, &__wait, \
431 TASK_INTERRUPTIBLE); \
433 finish_wait(&wq, &__wait); \
436 if (!signal_pending(current)) { \
440 ret = -ERESTARTSYS; \
441 abort_exclusive_wait(&wq, &__wait, \
442 TASK_INTERRUPTIBLE, NULL); \
447 #define wait_event_interruptible_exclusive(wq, condition) \
451 __wait_event_interruptible_exclusive(wq, condition, __ret);\
456 #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \
459 DEFINE_WAIT(__wait); \
461 __wait.flags |= WQ_FLAG_EXCLUSIVE; \
463 if (likely(list_empty(&__wait.task_list))) \
464 __add_wait_queue_tail(&(wq), &__wait); \
465 set_current_state(TASK_INTERRUPTIBLE); \
466 if (signal_pending(current)) { \
467 __ret = -ERESTARTSYS; \
471 spin_unlock_irq(&(wq).lock); \
473 spin_unlock(&(wq).lock); \
476 spin_lock_irq(&(wq).lock); \
478 spin_lock(&(wq).lock); \
479 } while (!(condition)); \
480 __remove_wait_queue(&(wq), &__wait); \
481 __set_current_state(TASK_RUNNING); \
487 * wait_event_interruptible_locked - sleep until a condition gets true
488 * @wq: the waitqueue to wait on
489 * @condition: a C expression for the event to wait for
491 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
492 * @condition evaluates to true or a signal is received.
493 * The @condition is checked each time the waitqueue @wq is woken up.
495 * It must be called with wq.lock being held. This spinlock is
496 * unlocked while sleeping but @condition testing is done while lock
497 * is held and when this macro exits the lock is held.
499 * The lock is locked/unlocked using spin_lock()/spin_unlock()
500 * functions which must match the way they are locked/unlocked outside
503 * wake_up_locked() has to be called after changing any variable that could
504 * change the result of the wait condition.
506 * The function will return -ERESTARTSYS if it was interrupted by a
507 * signal and 0 if @condition evaluated to true.
509 #define wait_event_interruptible_locked(wq, condition) \
511 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0))
514 * wait_event_interruptible_locked_irq - sleep until a condition gets true
515 * @wq: the waitqueue to wait on
516 * @condition: a C expression for the event to wait for
518 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
519 * @condition evaluates to true or a signal is received.
520 * The @condition is checked each time the waitqueue @wq is woken up.
522 * It must be called with wq.lock being held. This spinlock is
523 * unlocked while sleeping but @condition testing is done while lock
524 * is held and when this macro exits the lock is held.
526 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
527 * functions which must match the way they are locked/unlocked outside
530 * wake_up_locked() has to be called after changing any variable that could
531 * change the result of the wait condition.
533 * The function will return -ERESTARTSYS if it was interrupted by a
534 * signal and 0 if @condition evaluated to true.
536 #define wait_event_interruptible_locked_irq(wq, condition) \
538 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1))
541 * wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true
542 * @wq: the waitqueue to wait on
543 * @condition: a C expression for the event to wait for
545 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
546 * @condition evaluates to true or a signal is received.
547 * The @condition is checked each time the waitqueue @wq is woken up.
549 * It must be called with wq.lock being held. This spinlock is
550 * unlocked while sleeping but @condition testing is done while lock
551 * is held and when this macro exits the lock is held.
553 * The lock is locked/unlocked using spin_lock()/spin_unlock()
554 * functions which must match the way they are locked/unlocked outside
557 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
558 * set thus when other process waits process on the list if this
559 * process is awaken further processes are not considered.
561 * wake_up_locked() has to be called after changing any variable that could
562 * change the result of the wait condition.
564 * The function will return -ERESTARTSYS if it was interrupted by a
565 * signal and 0 if @condition evaluated to true.
567 #define wait_event_interruptible_exclusive_locked(wq, condition) \
569 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0))
572 * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true
573 * @wq: the waitqueue to wait on
574 * @condition: a C expression for the event to wait for
576 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
577 * @condition evaluates to true or a signal is received.
578 * The @condition is checked each time the waitqueue @wq is woken up.
580 * It must be called with wq.lock being held. This spinlock is
581 * unlocked while sleeping but @condition testing is done while lock
582 * is held and when this macro exits the lock is held.
584 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
585 * functions which must match the way they are locked/unlocked outside
588 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
589 * set thus when other process waits process on the list if this
590 * process is awaken further processes are not considered.
592 * wake_up_locked() has to be called after changing any variable that could
593 * change the result of the wait condition.
595 * The function will return -ERESTARTSYS if it was interrupted by a
596 * signal and 0 if @condition evaluated to true.
598 #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
600 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
604 #define __wait_event_killable(wq, condition, ret) \
606 DEFINE_WAIT(__wait); \
609 prepare_to_wait(&wq, &__wait, TASK_KILLABLE); \
612 if (!fatal_signal_pending(current)) { \
616 ret = -ERESTARTSYS; \
619 finish_wait(&wq, &__wait); \
623 * wait_event_killable - sleep until a condition gets true
624 * @wq: the waitqueue to wait on
625 * @condition: a C expression for the event to wait for
627 * The process is put to sleep (TASK_KILLABLE) until the
628 * @condition evaluates to true or a signal is received.
629 * The @condition is checked each time the waitqueue @wq is woken up.
631 * wake_up() has to be called after changing any variable that could
632 * change the result of the wait condition.
634 * The function will return -ERESTARTSYS if it was interrupted by a
635 * signal and 0 if @condition evaluated to true.
637 #define wait_event_killable(wq, condition) \
641 __wait_event_killable(wq, condition, __ret); \
646 #define __wait_event_lock_irq(wq, condition, lock, cmd) \
648 DEFINE_WAIT(__wait); \
651 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
654 spin_unlock_irq(&lock); \
657 spin_lock_irq(&lock); \
659 finish_wait(&wq, &__wait); \
663 * wait_event_lock_irq_cmd - sleep until a condition gets true. The
664 * condition is checked under the lock. This
665 * is expected to be called with the lock
667 * @wq: the waitqueue to wait on
668 * @condition: a C expression for the event to wait for
669 * @lock: a locked spinlock_t, which will be released before cmd
670 * and schedule() and reacquired afterwards.
671 * @cmd: a command which is invoked outside the critical section before
674 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
675 * @condition evaluates to true. The @condition is checked each time
676 * the waitqueue @wq is woken up.
678 * wake_up() has to be called after changing any variable that could
679 * change the result of the wait condition.
681 * This is supposed to be called while holding the lock. The lock is
682 * dropped before invoking the cmd and going to sleep and is reacquired
685 #define wait_event_lock_irq_cmd(wq, condition, lock, cmd) \
689 __wait_event_lock_irq(wq, condition, lock, cmd); \
693 * wait_event_lock_irq - sleep until a condition gets true. The
694 * condition is checked under the lock. This
695 * is expected to be called with the lock
697 * @wq: the waitqueue to wait on
698 * @condition: a C expression for the event to wait for
699 * @lock: a locked spinlock_t, which will be released before schedule()
700 * and reacquired afterwards.
702 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
703 * @condition evaluates to true. The @condition is checked each time
704 * the waitqueue @wq is woken up.
706 * wake_up() has to be called after changing any variable that could
707 * change the result of the wait condition.
709 * This is supposed to be called while holding the lock. The lock is
710 * dropped before going to sleep and is reacquired afterwards.
712 #define wait_event_lock_irq(wq, condition, lock) \
716 __wait_event_lock_irq(wq, condition, lock, ); \
720 #define __wait_event_interruptible_lock_irq(wq, condition, \
723 DEFINE_WAIT(__wait); \
726 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
729 if (signal_pending(current)) { \
730 ret = -ERESTARTSYS; \
733 spin_unlock_irq(&lock); \
736 spin_lock_irq(&lock); \
738 finish_wait(&wq, &__wait); \
742 * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
743 * The condition is checked under the lock. This is expected to
744 * be called with the lock taken.
745 * @wq: the waitqueue to wait on
746 * @condition: a C expression for the event to wait for
747 * @lock: a locked spinlock_t, which will be released before cmd and
748 * schedule() and reacquired afterwards.
749 * @cmd: a command which is invoked outside the critical section before
752 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
753 * @condition evaluates to true or a signal is received. The @condition is
754 * checked each time the waitqueue @wq is woken up.
756 * wake_up() has to be called after changing any variable that could
757 * change the result of the wait condition.
759 * This is supposed to be called while holding the lock. The lock is
760 * dropped before invoking the cmd and going to sleep and is reacquired
763 * The macro will return -ERESTARTSYS if it was interrupted by a signal
764 * and 0 if @condition evaluated to true.
766 #define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd) \
771 __wait_event_interruptible_lock_irq(wq, condition, \
777 * wait_event_interruptible_lock_irq - sleep until a condition gets true.
778 * The condition is checked under the lock. This is expected
779 * to be called with the lock taken.
780 * @wq: the waitqueue to wait on
781 * @condition: a C expression for the event to wait for
782 * @lock: a locked spinlock_t, which will be released before schedule()
783 * and reacquired afterwards.
785 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
786 * @condition evaluates to true or signal is received. The @condition is
787 * checked each time the waitqueue @wq is woken up.
789 * wake_up() has to be called after changing any variable that could
790 * change the result of the wait condition.
792 * This is supposed to be called while holding the lock. The lock is
793 * dropped before going to sleep and is reacquired afterwards.
795 * The macro will return -ERESTARTSYS if it was interrupted by a signal
796 * and 0 if @condition evaluated to true.
798 #define wait_event_interruptible_lock_irq(wq, condition, lock) \
803 __wait_event_interruptible_lock_irq(wq, condition, \
810 * These are the old interfaces to sleep waiting for an event.
811 * They are racy. DO NOT use them, use the wait_event* interfaces above.
812 * We plan to remove these interfaces.
814 extern void sleep_on(wait_queue_head_t *q);
815 extern long sleep_on_timeout(wait_queue_head_t *q,
816 signed long timeout);
817 extern void interruptible_sleep_on(wait_queue_head_t *q);
818 extern long interruptible_sleep_on_timeout(wait_queue_head_t *q,
819 signed long timeout);
822 * Waitqueues which are removed from the waitqueue_head at wakeup time
824 void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
825 void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state);
826 void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
827 void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait,
828 unsigned int mode, void *key);
829 int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
830 int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
832 #define DEFINE_WAIT_FUNC(name, function) \
833 wait_queue_t name = { \
834 .private = current, \
836 .task_list = LIST_HEAD_INIT((name).task_list), \
839 #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
841 #define DEFINE_WAIT_BIT(name, word, bit) \
842 struct wait_bit_queue name = { \
843 .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \
845 .private = current, \
846 .func = wake_bit_function, \
848 LIST_HEAD_INIT((name).wait.task_list), \
852 #define init_wait(wait) \
854 (wait)->private = current; \
855 (wait)->func = autoremove_wake_function; \
856 INIT_LIST_HEAD(&(wait)->task_list); \
861 * wait_on_bit - wait for a bit to be cleared
862 * @word: the word being waited on, a kernel virtual address
863 * @bit: the bit of the word being waited on
864 * @action: the function used to sleep, which may take special actions
865 * @mode: the task state to sleep in
867 * There is a standard hashed waitqueue table for generic use. This
868 * is the part of the hashtable's accessor API that waits on a bit.
869 * For instance, if one were to have waiters on a bitflag, one would
870 * call wait_on_bit() in threads waiting for the bit to clear.
871 * One uses wait_on_bit() where one is waiting for the bit to clear,
872 * but has no intention of setting it.
874 static inline int wait_on_bit(void *word, int bit,
875 int (*action)(void *), unsigned mode)
877 if (!test_bit(bit, word))
879 return out_of_line_wait_on_bit(word, bit, action, mode);
883 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
884 * @word: the word being waited on, a kernel virtual address
885 * @bit: the bit of the word being waited on
886 * @action: the function used to sleep, which may take special actions
887 * @mode: the task state to sleep in
889 * There is a standard hashed waitqueue table for generic use. This
890 * is the part of the hashtable's accessor API that waits on a bit
891 * when one intends to set it, for instance, trying to lock bitflags.
892 * For instance, if one were to have waiters trying to set bitflag
893 * and waiting for it to clear before setting it, one would call
894 * wait_on_bit() in threads waiting to be able to set the bit.
895 * One uses wait_on_bit_lock() where one is waiting for the bit to
896 * clear with the intention of setting it, and when done, clearing it.
898 static inline int wait_on_bit_lock(void *word, int bit,
899 int (*action)(void *), unsigned mode)
901 if (!test_and_set_bit(bit, word))
903 return out_of_line_wait_on_bit_lock(word, bit, action, mode);