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 finish_wait(&wq, &__wait); \
224 * wait_event_timeout - sleep until a condition gets true or a timeout elapses
225 * @wq: the waitqueue to wait on
226 * @condition: a C expression for the event to wait for
227 * @timeout: timeout, in jiffies
229 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
230 * @condition evaluates to true. The @condition is checked each time
231 * the waitqueue @wq is woken up.
233 * wake_up() has to be called after changing any variable that could
234 * change the result of the wait condition.
236 * The function returns 0 if the @timeout elapsed, and the remaining
237 * jiffies if the condition evaluated to true before the timeout elapsed.
239 #define wait_event_timeout(wq, condition, timeout) \
241 long __ret = timeout; \
243 __wait_event_timeout(wq, condition, __ret); \
247 #define __wait_event_interruptible(wq, condition, ret) \
249 DEFINE_WAIT(__wait); \
252 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
255 if (!signal_pending(current)) { \
259 ret = -ERESTARTSYS; \
262 finish_wait(&wq, &__wait); \
266 * wait_event_interruptible - sleep until a condition gets true
267 * @wq: the waitqueue to wait on
268 * @condition: a C expression for the event to wait for
270 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
271 * @condition evaluates to true or a signal is received.
272 * The @condition is checked each time the waitqueue @wq is woken up.
274 * wake_up() has to be called after changing any variable that could
275 * change the result of the wait condition.
277 * The function will return -ERESTARTSYS if it was interrupted by a
278 * signal and 0 if @condition evaluated to true.
280 #define wait_event_interruptible(wq, condition) \
284 __wait_event_interruptible(wq, condition, __ret); \
288 #define __wait_event_interruptible_timeout(wq, condition, ret) \
290 DEFINE_WAIT(__wait); \
293 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
296 if (!signal_pending(current)) { \
297 ret = schedule_timeout(ret); \
302 ret = -ERESTARTSYS; \
305 finish_wait(&wq, &__wait); \
309 * wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
310 * @wq: the waitqueue to wait on
311 * @condition: a C expression for the event to wait for
312 * @timeout: timeout, in jiffies
314 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
315 * @condition evaluates to true or a signal is received.
316 * The @condition is checked each time the waitqueue @wq is woken up.
318 * wake_up() has to be called after changing any variable that could
319 * change the result of the wait condition.
321 * The function returns 0 if the @timeout elapsed, -ERESTARTSYS if it
322 * was interrupted by a signal, and the remaining jiffies otherwise
323 * if the condition evaluated to true before the timeout elapsed.
325 #define wait_event_interruptible_timeout(wq, condition, timeout) \
327 long __ret = timeout; \
329 __wait_event_interruptible_timeout(wq, condition, __ret); \
333 #define __wait_event_hrtimeout(wq, condition, timeout, state) \
336 DEFINE_WAIT(__wait); \
337 struct hrtimer_sleeper __t; \
339 hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \
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, \
348 prepare_to_wait(&wq, &__wait, state); \
351 if (state == TASK_INTERRUPTIBLE && \
352 signal_pending(current)) { \
353 __ret = -ERESTARTSYS; \
363 hrtimer_cancel(&__t.timer); \
364 destroy_hrtimer_on_stack(&__t.timer); \
365 finish_wait(&wq, &__wait); \
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
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.
379 * wake_up() has to be called after changing any variable that could
380 * change the result of the wait condition.
382 * The function returns 0 if @condition became true, or -ETIME if the timeout
385 #define wait_event_hrtimeout(wq, condition, timeout) \
389 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
390 TASK_UNINTERRUPTIBLE); \
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
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.
404 * wake_up() has to be called after changing any variable that could
405 * change the result of the wait condition.
407 * The function returns 0 if @condition became true, -ERESTARTSYS if it was
408 * interrupted by a signal, or -ETIME if the timeout elapsed.
410 #define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
414 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
415 TASK_INTERRUPTIBLE); \
419 #define __wait_event_interruptible_exclusive(wq, condition, ret) \
421 DEFINE_WAIT(__wait); \
424 prepare_to_wait_exclusive(&wq, &__wait, \
425 TASK_INTERRUPTIBLE); \
427 finish_wait(&wq, &__wait); \
430 if (!signal_pending(current)) { \
434 ret = -ERESTARTSYS; \
435 abort_exclusive_wait(&wq, &__wait, \
436 TASK_INTERRUPTIBLE, NULL); \
441 #define wait_event_interruptible_exclusive(wq, condition) \
445 __wait_event_interruptible_exclusive(wq, condition, __ret);\
450 #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \
453 DEFINE_WAIT(__wait); \
455 __wait.flags |= WQ_FLAG_EXCLUSIVE; \
457 if (likely(list_empty(&__wait.task_list))) \
458 __add_wait_queue_tail(&(wq), &__wait); \
459 set_current_state(TASK_INTERRUPTIBLE); \
460 if (signal_pending(current)) { \
461 __ret = -ERESTARTSYS; \
465 spin_unlock_irq(&(wq).lock); \
467 spin_unlock(&(wq).lock); \
470 spin_lock_irq(&(wq).lock); \
472 spin_lock(&(wq).lock); \
473 } while (!(condition)); \
474 __remove_wait_queue(&(wq), &__wait); \
475 __set_current_state(TASK_RUNNING); \
481 * wait_event_interruptible_locked - sleep until a condition gets true
482 * @wq: the waitqueue to wait on
483 * @condition: a C expression for the event to wait for
485 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
486 * @condition evaluates to true or a signal is received.
487 * The @condition is checked each time the waitqueue @wq is woken up.
489 * It must be called with wq.lock being held. This spinlock is
490 * unlocked while sleeping but @condition testing is done while lock
491 * is held and when this macro exits the lock is held.
493 * The lock is locked/unlocked using spin_lock()/spin_unlock()
494 * functions which must match the way they are locked/unlocked outside
497 * wake_up_locked() has to be called after changing any variable that could
498 * change the result of the wait condition.
500 * The function will return -ERESTARTSYS if it was interrupted by a
501 * signal and 0 if @condition evaluated to true.
503 #define wait_event_interruptible_locked(wq, condition) \
505 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0))
508 * wait_event_interruptible_locked_irq - sleep until a condition gets true
509 * @wq: the waitqueue to wait on
510 * @condition: a C expression for the event to wait for
512 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
513 * @condition evaluates to true or a signal is received.
514 * The @condition is checked each time the waitqueue @wq is woken up.
516 * It must be called with wq.lock being held. This spinlock is
517 * unlocked while sleeping but @condition testing is done while lock
518 * is held and when this macro exits the lock is held.
520 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
521 * functions which must match the way they are locked/unlocked outside
524 * wake_up_locked() has to be called after changing any variable that could
525 * change the result of the wait condition.
527 * The function will return -ERESTARTSYS if it was interrupted by a
528 * signal and 0 if @condition evaluated to true.
530 #define wait_event_interruptible_locked_irq(wq, condition) \
532 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1))
535 * wait_event_interruptible_exclusive_locked - sleep exclusively until a condition gets true
536 * @wq: the waitqueue to wait on
537 * @condition: a C expression for the event to wait for
539 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
540 * @condition evaluates to true or a signal is received.
541 * The @condition is checked each time the waitqueue @wq is woken up.
543 * It must be called with wq.lock being held. This spinlock is
544 * unlocked while sleeping but @condition testing is done while lock
545 * is held and when this macro exits the lock is held.
547 * The lock is locked/unlocked using spin_lock()/spin_unlock()
548 * functions which must match the way they are locked/unlocked outside
551 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
552 * set thus when other process waits process on the list if this
553 * process is awaken further processes are not considered.
555 * wake_up_locked() has to be called after changing any variable that could
556 * change the result of the wait condition.
558 * The function will return -ERESTARTSYS if it was interrupted by a
559 * signal and 0 if @condition evaluated to true.
561 #define wait_event_interruptible_exclusive_locked(wq, condition) \
563 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0))
566 * wait_event_interruptible_exclusive_locked_irq - sleep until a condition gets true
567 * @wq: the waitqueue to wait on
568 * @condition: a C expression for the event to wait for
570 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
571 * @condition evaluates to true or a signal is received.
572 * The @condition is checked each time the waitqueue @wq is woken up.
574 * It must be called with wq.lock being held. This spinlock is
575 * unlocked while sleeping but @condition testing is done while lock
576 * is held and when this macro exits the lock is held.
578 * The lock is locked/unlocked using spin_lock_irq()/spin_unlock_irq()
579 * functions which must match the way they are locked/unlocked outside
582 * The process is put on the wait queue with an WQ_FLAG_EXCLUSIVE flag
583 * set thus when other process waits process on the list if this
584 * process is awaken further processes are not considered.
586 * wake_up_locked() has to be called after changing any variable that could
587 * change the result of the wait condition.
589 * The function will return -ERESTARTSYS if it was interrupted by a
590 * signal and 0 if @condition evaluated to true.
592 #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
594 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
598 #define __wait_event_killable(wq, condition, ret) \
600 DEFINE_WAIT(__wait); \
603 prepare_to_wait(&wq, &__wait, TASK_KILLABLE); \
606 if (!fatal_signal_pending(current)) { \
610 ret = -ERESTARTSYS; \
613 finish_wait(&wq, &__wait); \
617 * wait_event_killable - sleep until a condition gets true
618 * @wq: the waitqueue to wait on
619 * @condition: a C expression for the event to wait for
621 * The process is put to sleep (TASK_KILLABLE) until the
622 * @condition evaluates to true or a signal is received.
623 * The @condition is checked each time the waitqueue @wq is woken up.
625 * wake_up() has to be called after changing any variable that could
626 * change the result of the wait condition.
628 * The function will return -ERESTARTSYS if it was interrupted by a
629 * signal and 0 if @condition evaluated to true.
631 #define wait_event_killable(wq, condition) \
635 __wait_event_killable(wq, condition, __ret); \
640 #define __wait_event_lock_irq(wq, condition, lock, cmd) \
642 DEFINE_WAIT(__wait); \
645 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
648 spin_unlock_irq(&lock); \
651 spin_lock_irq(&lock); \
653 finish_wait(&wq, &__wait); \
657 * wait_event_lock_irq_cmd - sleep until a condition gets true. The
658 * condition is checked under the lock. This
659 * is expected to be called with the lock
661 * @wq: the waitqueue to wait on
662 * @condition: a C expression for the event to wait for
663 * @lock: a locked spinlock_t, which will be released before cmd
664 * and schedule() and reacquired afterwards.
665 * @cmd: a command which is invoked outside the critical section before
668 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
669 * @condition evaluates to true. The @condition is checked each time
670 * the waitqueue @wq is woken up.
672 * wake_up() has to be called after changing any variable that could
673 * change the result of the wait condition.
675 * This is supposed to be called while holding the lock. The lock is
676 * dropped before invoking the cmd and going to sleep and is reacquired
679 #define wait_event_lock_irq_cmd(wq, condition, lock, cmd) \
683 __wait_event_lock_irq(wq, condition, lock, cmd); \
687 * wait_event_lock_irq - sleep until a condition gets true. The
688 * condition is checked under the lock. This
689 * is expected to be called with the lock
691 * @wq: the waitqueue to wait on
692 * @condition: a C expression for the event to wait for
693 * @lock: a locked spinlock_t, which will be released before schedule()
694 * and reacquired afterwards.
696 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
697 * @condition evaluates to true. The @condition is checked each time
698 * the waitqueue @wq is woken up.
700 * wake_up() has to be called after changing any variable that could
701 * change the result of the wait condition.
703 * This is supposed to be called while holding the lock. The lock is
704 * dropped before going to sleep and is reacquired afterwards.
706 #define wait_event_lock_irq(wq, condition, lock) \
710 __wait_event_lock_irq(wq, condition, lock, ); \
714 #define __wait_event_interruptible_lock_irq(wq, condition, \
717 DEFINE_WAIT(__wait); \
720 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
723 if (signal_pending(current)) { \
724 ret = -ERESTARTSYS; \
727 spin_unlock_irq(&lock); \
730 spin_lock_irq(&lock); \
732 finish_wait(&wq, &__wait); \
736 * wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
737 * The condition is checked under the lock. This is expected to
738 * be called with the lock taken.
739 * @wq: the waitqueue to wait on
740 * @condition: a C expression for the event to wait for
741 * @lock: a locked spinlock_t, which will be released before cmd and
742 * schedule() and reacquired afterwards.
743 * @cmd: a command which is invoked outside the critical section before
746 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
747 * @condition evaluates to true or a signal is received. The @condition is
748 * checked each time the waitqueue @wq is woken up.
750 * wake_up() has to be called after changing any variable that could
751 * change the result of the wait condition.
753 * This is supposed to be called while holding the lock. The lock is
754 * dropped before invoking the cmd and going to sleep and is reacquired
757 * The macro will return -ERESTARTSYS if it was interrupted by a signal
758 * and 0 if @condition evaluated to true.
760 #define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd) \
765 __wait_event_interruptible_lock_irq(wq, condition, \
771 * wait_event_interruptible_lock_irq - sleep until a condition gets true.
772 * The condition is checked under the lock. This is expected
773 * to be called with the lock taken.
774 * @wq: the waitqueue to wait on
775 * @condition: a C expression for the event to wait for
776 * @lock: a locked spinlock_t, which will be released before schedule()
777 * and reacquired afterwards.
779 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
780 * @condition evaluates to true or signal is received. The @condition is
781 * checked each time the waitqueue @wq is woken up.
783 * wake_up() has to be called after changing any variable that could
784 * change the result of the wait condition.
786 * This is supposed to be called while holding the lock. The lock is
787 * dropped before going to sleep and is reacquired afterwards.
789 * The macro will return -ERESTARTSYS if it was interrupted by a signal
790 * and 0 if @condition evaluated to true.
792 #define wait_event_interruptible_lock_irq(wq, condition, lock) \
797 __wait_event_interruptible_lock_irq(wq, condition, \
804 * These are the old interfaces to sleep waiting for an event.
805 * They are racy. DO NOT use them, use the wait_event* interfaces above.
806 * We plan to remove these interfaces.
808 extern void sleep_on(wait_queue_head_t
*q
);
809 extern long sleep_on_timeout(wait_queue_head_t
*q
,
810 signed long timeout
);
811 extern void interruptible_sleep_on(wait_queue_head_t
*q
);
812 extern long interruptible_sleep_on_timeout(wait_queue_head_t
*q
,
813 signed long timeout
);
816 * Waitqueues which are removed from the waitqueue_head at wakeup time
818 void prepare_to_wait(wait_queue_head_t
*q
, wait_queue_t
*wait
, int state
);
819 void prepare_to_wait_exclusive(wait_queue_head_t
*q
, wait_queue_t
*wait
, int state
);
820 void finish_wait(wait_queue_head_t
*q
, wait_queue_t
*wait
);
821 void abort_exclusive_wait(wait_queue_head_t
*q
, wait_queue_t
*wait
,
822 unsigned int mode
, void *key
);
823 int autoremove_wake_function(wait_queue_t
*wait
, unsigned mode
, int sync
, void *key
);
824 int wake_bit_function(wait_queue_t
*wait
, unsigned mode
, int sync
, void *key
);
826 #define DEFINE_WAIT_FUNC(name, function) \
827 wait_queue_t name = { \
828 .private = current, \
830 .task_list = LIST_HEAD_INIT((name).task_list), \
833 #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
835 #define DEFINE_WAIT_BIT(name, word, bit) \
836 struct wait_bit_queue name = { \
837 .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \
839 .private = current, \
840 .func = wake_bit_function, \
842 LIST_HEAD_INIT((name).wait.task_list), \
846 #define init_wait(wait) \
848 (wait)->private = current; \
849 (wait)->func = autoremove_wake_function; \
850 INIT_LIST_HEAD(&(wait)->task_list); \
855 * wait_on_bit - wait for a bit to be cleared
856 * @word: the word being waited on, a kernel virtual address
857 * @bit: the bit of the word being waited on
858 * @action: the function used to sleep, which may take special actions
859 * @mode: the task state to sleep in
861 * There is a standard hashed waitqueue table for generic use. This
862 * is the part of the hashtable's accessor API that waits on a bit.
863 * For instance, if one were to have waiters on a bitflag, one would
864 * call wait_on_bit() in threads waiting for the bit to clear.
865 * One uses wait_on_bit() where one is waiting for the bit to clear,
866 * but has no intention of setting it.
868 static inline int wait_on_bit(void *word
, int bit
,
869 int (*action
)(void *), unsigned mode
)
871 if (!test_bit(bit
, word
))
873 return out_of_line_wait_on_bit(word
, bit
, action
, mode
);
877 * wait_on_bit_lock - wait for a bit to be cleared, when wanting to set it
878 * @word: the word being waited on, a kernel virtual address
879 * @bit: the bit of the word being waited on
880 * @action: the function used to sleep, which may take special actions
881 * @mode: the task state to sleep in
883 * There is a standard hashed waitqueue table for generic use. This
884 * is the part of the hashtable's accessor API that waits on a bit
885 * when one intends to set it, for instance, trying to lock bitflags.
886 * For instance, if one were to have waiters trying to set bitflag
887 * and waiting for it to clear before setting it, one would call
888 * wait_on_bit() in threads waiting to be able to set the bit.
889 * One uses wait_on_bit_lock() where one is waiting for the bit to
890 * clear with the intention of setting it, and when done, clearing it.
892 static inline int wait_on_bit_lock(void *word
, int bit
,
893 int (*action
)(void *), unsigned mode
)
895 if (!test_and_set_bit(bit
, word
))
897 return out_of_line_wait_on_bit_lock(word
, bit
, action
, mode
);