13
14
int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
15
16
struct __wait_queue {
17
18
#define WQ_FLAG_EXCLUSIVE 0x01
19
wait_queue_func_t func;
20
struct list_head task_list;
20
wait_queue_func_t func;
21
struct list_head task_list;
23
24
struct wait_bit_key {
26
#define WAIT_ATOMIC_T_BIT_NR -1
27
#define WAIT_ATOMIC_T_BIT_NR -1
29
30
struct wait_bit_queue {
30
struct wait_bit_key key;
31
struct wait_bit_key key;
34
35
struct __wait_queue_head {
36
struct list_head task_list;
37
struct list_head task_list;
38
39
typedef struct __wait_queue_head wait_queue_head_t;
85
86
static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
89
q->func = default_wake_function;
90
q->func = default_wake_function;
92
static inline void init_waitqueue_func_entry(wait_queue_t *q,
93
wait_queue_func_t func)
94
init_waitqueue_func_entry(wait_queue_t *q, wait_queue_func_t func)
100
101
static inline int waitqueue_active(wait_queue_head_t *q)
115
116
* Used for wake-one threads:
117
static inline void __add_wait_queue_exclusive(wait_queue_head_t *q,
119
__add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
120
121
wait->flags |= WQ_FLAG_EXCLUSIVE;
121
122
__add_wait_queue(q, wait);
127
128
list_add_tail(&new->task_list, &head->task_list);
130
static inline void __add_wait_queue_tail_exclusive(wait_queue_head_t *q,
132
__add_wait_queue_tail_exclusive(wait_queue_head_t *q, wait_queue_t *wait)
133
134
wait->flags |= WQ_FLAG_EXCLUSIVE;
134
135
__add_wait_queue_tail(q, wait);
137
static inline void __remove_wait_queue(wait_queue_head_t *head,
139
__remove_wait_queue(wait_queue_head_t *head, wait_queue_t *old)
140
141
list_del(&old->task_list);
143
144
void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
144
145
void __wake_up_locked_key(wait_queue_head_t *q, unsigned int mode, void *key);
145
void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr,
146
void __wake_up_sync_key(wait_queue_head_t *q, unsigned int mode, int nr, void *key);
147
147
void __wake_up_locked(wait_queue_head_t *q, unsigned int mode, int nr);
148
148
void __wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr);
149
149
void __wake_up_bit(wait_queue_head_t *, void *, int);
171
171
* Wakeup macros to be used to report events to the targets.
173
#define wake_up_poll(x, m) \
173
#define wake_up_poll(x, m) \
174
174
__wake_up(x, TASK_NORMAL, 1, (void *) (m))
175
#define wake_up_locked_poll(x, m) \
175
#define wake_up_locked_poll(x, m) \
176
176
__wake_up_locked_key((x), TASK_NORMAL, (void *) (m))
177
#define wake_up_interruptible_poll(x, m) \
177
#define wake_up_interruptible_poll(x, m) \
178
178
__wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m))
179
179
#define wake_up_interruptible_sync_poll(x, m) \
180
180
__wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
182
#define __wait_event(wq, condition) \
184
DEFINE_WAIT(__wait); \
182
#define ___wait_cond_timeout(condition) \
184
bool __cond = (condition); \
185
if (__cond && !__ret) \
190
#define ___wait_is_interruptible(state) \
191
(!__builtin_constant_p(state) || \
192
state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \
194
#define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
197
wait_queue_t __wait; \
200
INIT_LIST_HEAD(&__wait.task_list); \
202
__wait.flags = WQ_FLAG_EXCLUSIVE; \
187
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
207
long __int = prepare_to_wait_event(&wq, &__wait, state);\
212
if (___wait_is_interruptible(state) && __int) { \
215
abort_exclusive_wait(&wq, &__wait, \
192
224
finish_wait(&wq, &__wait); \
228
#define __wait_event(wq, condition) \
229
(void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
196
233
* wait_event - sleep until a condition gets true
204
241
* wake_up() has to be called after changing any variable that could
205
242
* change the result of the wait condition.
207
#define wait_event(wq, condition) \
244
#define wait_event(wq, condition) \
211
248
__wait_event(wq, condition); \
214
#define __wait_event_timeout(wq, condition, ret) \
216
DEFINE_WAIT(__wait); \
219
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
222
ret = schedule_timeout(ret); \
226
if (!ret && (condition)) \
228
finish_wait(&wq, &__wait); \
251
#define __wait_event_timeout(wq, condition, timeout) \
252
___wait_event(wq, ___wait_cond_timeout(condition), \
253
TASK_UNINTERRUPTIBLE, 0, timeout, \
254
__ret = schedule_timeout(__ret))
232
257
* wait_event_timeout - sleep until a condition gets true or a timeout elapses
248
273
#define wait_event_timeout(wq, condition, timeout) \
250
275
long __ret = timeout; \
252
__wait_event_timeout(wq, condition, __ret); \
276
if (!___wait_cond_timeout(condition)) \
277
__ret = __wait_event_timeout(wq, condition, timeout); \
256
#define __wait_event_interruptible(wq, condition, ret) \
281
#define __wait_event_cmd(wq, condition, cmd1, cmd2) \
282
(void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
283
cmd1; schedule(); cmd2)
286
* wait_event_cmd - sleep until a condition gets true
287
* @wq: the waitqueue to wait on
288
* @condition: a C expression for the event to wait for
289
* cmd1: the command will be executed before sleep
290
* cmd2: the command will be executed after sleep
292
* The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
293
* @condition evaluates to true. The @condition is checked each time
294
* the waitqueue @wq is woken up.
296
* wake_up() has to be called after changing any variable that could
297
* change the result of the wait condition.
299
#define wait_event_cmd(wq, condition, cmd1, cmd2) \
258
DEFINE_WAIT(__wait); \
261
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
264
if (!signal_pending(current)) { \
268
ret = -ERESTARTSYS; \
271
finish_wait(&wq, &__wait); \
303
__wait_event_cmd(wq, condition, cmd1, cmd2); \
306
#define __wait_event_interruptible(wq, condition) \
307
___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \
275
311
* wait_event_interruptible - sleep until a condition gets true
276
312
* @wq: the waitqueue to wait on
292
328
if (!(condition)) \
293
__wait_event_interruptible(wq, condition, __ret); \
329
__ret = __wait_event_interruptible(wq, condition); \
297
#define __wait_event_interruptible_timeout(wq, condition, ret) \
299
DEFINE_WAIT(__wait); \
302
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
305
if (!signal_pending(current)) { \
306
ret = schedule_timeout(ret); \
311
ret = -ERESTARTSYS; \
314
if (!ret && (condition)) \
316
finish_wait(&wq, &__wait); \
333
#define __wait_event_interruptible_timeout(wq, condition, timeout) \
334
___wait_event(wq, ___wait_cond_timeout(condition), \
335
TASK_INTERRUPTIBLE, 0, timeout, \
336
__ret = schedule_timeout(__ret))
320
339
* wait_event_interruptible_timeout - sleep until a condition gets true or a timeout elapses
337
356
#define wait_event_interruptible_timeout(wq, condition, timeout) \
339
358
long __ret = timeout; \
341
__wait_event_interruptible_timeout(wq, condition, __ret); \
359
if (!___wait_cond_timeout(condition)) \
360
__ret = __wait_event_interruptible_timeout(wq, \
361
condition, timeout); \
345
365
#define __wait_event_hrtimeout(wq, condition, timeout, state) \
348
DEFINE_WAIT(__wait); \
349
368
struct hrtimer_sleeper __t; \
351
370
hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, \
356
375
current->timer_slack_ns, \
357
376
HRTIMER_MODE_REL); \
360
prepare_to_wait(&wq, &__wait, state); \
363
if (state == TASK_INTERRUPTIBLE && \
364
signal_pending(current)) { \
365
__ret = -ERESTARTSYS; \
378
__ret = ___wait_event(wq, condition, state, 0, 0, \
368
379
if (!__t.task) { \
369
380
__ret = -ETIME; \
375
385
hrtimer_cancel(&__t.timer); \
376
386
destroy_hrtimer_on_stack(&__t.timer); \
377
finish_wait(&wq, &__wait); \
431
#define __wait_event_interruptible_exclusive(wq, condition, ret) \
433
DEFINE_WAIT(__wait); \
436
prepare_to_wait_exclusive(&wq, &__wait, \
437
TASK_INTERRUPTIBLE); \
439
finish_wait(&wq, &__wait); \
442
if (!signal_pending(current)) { \
446
ret = -ERESTARTSYS; \
447
abort_exclusive_wait(&wq, &__wait, \
448
TASK_INTERRUPTIBLE, NULL); \
440
#define __wait_event_interruptible_exclusive(wq, condition) \
441
___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
453
444
#define wait_event_interruptible_exclusive(wq, condition) \
456
447
if (!(condition)) \
457
__wait_event_interruptible_exclusive(wq, condition, __ret);\
448
__ret = __wait_event_interruptible_exclusive(wq, condition);\
606
597
? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
610
#define __wait_event_killable(wq, condition, ret) \
612
DEFINE_WAIT(__wait); \
615
prepare_to_wait(&wq, &__wait, TASK_KILLABLE); \
618
if (!fatal_signal_pending(current)) { \
622
ret = -ERESTARTSYS; \
625
finish_wait(&wq, &__wait); \
600
#define __wait_event_killable(wq, condition) \
601
___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
629
604
* wait_event_killable - sleep until a condition gets true
646
621
if (!(condition)) \
647
__wait_event_killable(wq, condition, __ret); \
622
__ret = __wait_event_killable(wq, condition); \
652
627
#define __wait_event_lock_irq(wq, condition, lock, cmd) \
654
DEFINE_WAIT(__wait); \
657
prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
660
spin_unlock_irq(&lock); \
663
spin_lock_irq(&lock); \
665
finish_wait(&wq, &__wait); \
628
(void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
629
spin_unlock_irq(&lock); \
632
spin_lock_irq(&lock))
669
635
* wait_event_lock_irq_cmd - sleep until a condition gets true. The
726
#define __wait_event_interruptible_lock_irq(wq, condition, \
729
DEFINE_WAIT(__wait); \
732
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
735
if (signal_pending(current)) { \
736
ret = -ERESTARTSYS; \
739
spin_unlock_irq(&lock); \
742
spin_lock_irq(&lock); \
744
finish_wait(&wq, &__wait); \
692
#define __wait_event_interruptible_lock_irq(wq, condition, lock, cmd) \
693
___wait_event(wq, condition, TASK_INTERRUPTIBLE, 0, 0, \
694
spin_unlock_irq(&lock); \
697
spin_lock_irq(&lock))
748
700
* wait_event_interruptible_lock_irq_cmd - sleep until a condition gets true.
772
724
#define wait_event_interruptible_lock_irq_cmd(wq, condition, lock, cmd) \
776
727
if (!(condition)) \
777
__wait_event_interruptible_lock_irq(wq, condition, \
728
__ret = __wait_event_interruptible_lock_irq(wq, \
729
condition, lock, cmd); \
804
755
#define wait_event_interruptible_lock_irq(wq, condition, lock) \
808
758
if (!(condition)) \
809
__wait_event_interruptible_lock_irq(wq, condition, \
759
__ret = __wait_event_interruptible_lock_irq(wq, \
814
764
#define __wait_event_interruptible_lock_irq_timeout(wq, condition, \
817
DEFINE_WAIT(__wait); \
820
prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
823
if (signal_pending(current)) { \
824
ret = -ERESTARTSYS; \
827
spin_unlock_irq(&lock); \
828
ret = schedule_timeout(ret); \
829
spin_lock_irq(&lock); \
833
finish_wait(&wq, &__wait); \
766
___wait_event(wq, ___wait_cond_timeout(condition), \
767
TASK_INTERRUPTIBLE, 0, timeout, \
768
spin_unlock_irq(&lock); \
769
__ret = schedule_timeout(__ret); \
770
spin_lock_irq(&lock));
837
* wait_event_interruptible_lock_irq_timeout - sleep until a condition gets true or a timeout elapses.
838
* The condition is checked under the lock. This is expected
839
* to be called with the lock taken.
773
* wait_event_interruptible_lock_irq_timeout - sleep until a condition gets
774
* true or a timeout elapses. The condition is checked under
775
* the lock. This is expected to be called with the lock taken.
840
776
* @wq: the waitqueue to wait on
841
777
* @condition: a C expression for the event to wait for
842
778
* @lock: a locked spinlock_t, which will be released before schedule()
860
796
#define wait_event_interruptible_lock_irq_timeout(wq, condition, lock, \
863
int __ret = timeout; \
866
__wait_event_interruptible_lock_irq_timeout( \
867
wq, condition, lock, __ret); \
799
long __ret = timeout; \
800
if (!___wait_cond_timeout(condition)) \
801
__ret = __wait_event_interruptible_lock_irq_timeout( \
802
wq, condition, lock, timeout); \
875
810
* We plan to remove these interfaces.
877
812
extern void sleep_on(wait_queue_head_t *q);
878
extern long sleep_on_timeout(wait_queue_head_t *q,
879
signed long timeout);
813
extern long sleep_on_timeout(wait_queue_head_t *q, signed long timeout);
880
814
extern void interruptible_sleep_on(wait_queue_head_t *q);
881
extern long interruptible_sleep_on_timeout(wait_queue_head_t *q,
882
signed long timeout);
815
extern long interruptible_sleep_on_timeout(wait_queue_head_t *q, signed long timeout);
885
818
* Waitqueues which are removed from the waitqueue_head at wakeup time
887
820
void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
888
821
void prepare_to_wait_exclusive(wait_queue_head_t *q, wait_queue_t *wait, int state);
822
long prepare_to_wait_event(wait_queue_head_t *q, wait_queue_t *wait, int state);
889
823
void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
890
void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait,
891
unsigned int mode, void *key);
824
void abort_exclusive_wait(wait_queue_head_t *q, wait_queue_t *wait, unsigned int mode, void *key);
892
825
int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
893
826
int wake_bit_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
934
867
* One uses wait_on_bit() where one is waiting for the bit to clear,
935
868
* but has no intention of setting it.
937
static inline int wait_on_bit(void *word, int bit,
938
int (*action)(void *), unsigned mode)
871
wait_on_bit(void *word, int bit, int (*action)(void *), unsigned mode)
940
873
if (!test_bit(bit, word))
958
891
* One uses wait_on_bit_lock() where one is waiting for the bit to
959
892
* clear with the intention of setting it, and when done, clearing it.
961
static inline int wait_on_bit_lock(void *word, int bit,
962
int (*action)(void *), unsigned mode)
895
wait_on_bit_lock(void *word, int bit, int (*action)(void *), unsigned mode)
964
897
if (!test_and_set_bit(bit, word))