1
2#ifndef _LINUX_WAIT_H
3#define _LINUX_WAIT_H
4
5
6
7#include <linux/list.h>
8#include <linux/stddef.h>
9#include <linux/spinlock.h>
10
11#include <asm/current.h>
12#include <uapi/linux/wait.h>
13
14typedef struct wait_queue_entry wait_queue_entry_t;
15
16typedef int (*wait_queue_func_t)(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
17int default_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int flags, void *key);
18
19
20#define WQ_FLAG_EXCLUSIVE 0x01
21#define WQ_FLAG_WOKEN 0x02
22#define WQ_FLAG_BOOKMARK 0x04
23
24
25
26
27struct wait_queue_entry {
28 unsigned int flags;
29 void *private;
30 wait_queue_func_t func;
31 struct list_head entry;
32};
33
34struct wait_queue_head {
35 spinlock_t lock;
36 struct list_head head;
37};
38typedef struct wait_queue_head wait_queue_head_t;
39
40struct task_struct;
41
42
43
44
45
46#define __WAITQUEUE_INITIALIZER(name, tsk) { \
47 .private = tsk, \
48 .func = default_wake_function, \
49 .entry = { NULL, NULL } }
50
51#define DECLARE_WAITQUEUE(name, tsk) \
52 struct wait_queue_entry name = __WAITQUEUE_INITIALIZER(name, tsk)
53
54#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
55 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
56 .head = { &(name).head, &(name).head } }
57
58#define DECLARE_WAIT_QUEUE_HEAD(name) \
59 struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
60
61extern void __init_waitqueue_head(struct wait_queue_head *wq_head, const char *name, struct lock_class_key *);
62
63#define init_waitqueue_head(wq_head) \
64 do { \
65 static struct lock_class_key __key; \
66 \
67 __init_waitqueue_head((wq_head), #wq_head, &__key); \
68 } while (0)
69
70#ifdef CONFIG_LOCKDEP
71# define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
72 ({ init_waitqueue_head(&name); name; })
73# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
74 struct wait_queue_head name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
75#else
76# define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
77#endif
78
79static inline void init_waitqueue_entry(struct wait_queue_entry *wq_entry, struct task_struct *p)
80{
81 wq_entry->flags = 0;
82 wq_entry->private = p;
83 wq_entry->func = default_wake_function;
84}
85
86static inline void
87init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func)
88{
89 wq_entry->flags = 0;
90 wq_entry->private = NULL;
91 wq_entry->func = func;
92}
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124static inline int waitqueue_active(struct wait_queue_head *wq_head)
125{
126 return !list_empty(&wq_head->head);
127}
128
129
130
131
132
133
134
135
136
137static inline bool wq_has_sleeper(struct wait_queue_head *wq_head)
138{
139
140
141
142
143
144
145
146 smp_mb();
147 return waitqueue_active(wq_head);
148}
149
150extern void add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
151extern void add_wait_queue_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
152extern void remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
153
154static inline void __add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
155{
156 list_add(&wq_entry->entry, &wq_head->head);
157}
158
159
160
161
162static inline void
163__add_wait_queue_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
164{
165 wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
166 __add_wait_queue(wq_head, wq_entry);
167}
168
169static inline void __add_wait_queue_entry_tail(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
170{
171 list_add_tail(&wq_entry->entry, &wq_head->head);
172}
173
174static inline void
175__add_wait_queue_entry_tail_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
176{
177 wq_entry->flags |= WQ_FLAG_EXCLUSIVE;
178 __add_wait_queue_entry_tail(wq_head, wq_entry);
179}
180
181static inline void
182__remove_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
183{
184 list_del(&wq_entry->entry);
185}
186
187void __wake_up(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
188void __wake_up_locked_key(struct wait_queue_head *wq_head, unsigned int mode, void *key);
189void __wake_up_locked_key_bookmark(struct wait_queue_head *wq_head,
190 unsigned int mode, void *key, wait_queue_entry_t *bookmark);
191void __wake_up_sync_key(struct wait_queue_head *wq_head, unsigned int mode, int nr, void *key);
192void __wake_up_locked(struct wait_queue_head *wq_head, unsigned int mode, int nr);
193void __wake_up_sync(struct wait_queue_head *wq_head, unsigned int mode, int nr);
194
195#define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
196#define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
197#define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL)
198#define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1)
199#define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0)
200
201#define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
202#define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
203#define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
204#define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
205
206
207
208
209#define poll_to_key(m) ((void *)(__force uintptr_t)(__poll_t)(m))
210#define key_to_poll(m) ((__force __poll_t)(uintptr_t)(void *)(m))
211#define wake_up_poll(x, m) \
212 __wake_up(x, TASK_NORMAL, 1, poll_to_key(m))
213#define wake_up_locked_poll(x, m) \
214 __wake_up_locked_key((x), TASK_NORMAL, poll_to_key(m))
215#define wake_up_interruptible_poll(x, m) \
216 __wake_up(x, TASK_INTERRUPTIBLE, 1, poll_to_key(m))
217#define wake_up_interruptible_sync_poll(x, m) \
218 __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, poll_to_key(m))
219
220#define ___wait_cond_timeout(condition) \
221({ \
222 bool __cond = (condition); \
223 if (__cond && !__ret) \
224 __ret = 1; \
225 __cond || !__ret; \
226})
227
228#define ___wait_is_interruptible(state) \
229 (!__builtin_constant_p(state) || \
230 state == TASK_INTERRUPTIBLE || state == TASK_KILLABLE) \
231
232extern void init_wait_entry(struct wait_queue_entry *wq_entry, int flags);
233
234
235
236
237
238
239
240
241
242
243
244
245
246#define ___wait_event(wq_head, condition, state, exclusive, ret, cmd) \
247({ \
248 __label__ __out; \
249 struct wait_queue_entry __wq_entry; \
250 long __ret = ret; \
251 \
252 init_wait_entry(&__wq_entry, exclusive ? WQ_FLAG_EXCLUSIVE : 0); \
253 for (;;) { \
254 long __int = prepare_to_wait_event(&wq_head, &__wq_entry, state);\
255 \
256 if (condition) \
257 break; \
258 \
259 if (___wait_is_interruptible(state) && __int) { \
260 __ret = __int; \
261 goto __out; \
262 } \
263 \
264 cmd; \
265 } \
266 finish_wait(&wq_head, &__wq_entry); \
267__out: __ret; \
268})
269
270#define __wait_event(wq_head, condition) \
271 (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
272 schedule())
273
274
275
276
277
278
279
280
281
282
283
284
285
286#define wait_event(wq_head, condition) \
287do { \
288 might_sleep(); \
289 if (condition) \
290 break; \
291 __wait_event(wq_head, condition); \
292} while (0)
293
294#define __io_wait_event(wq_head, condition) \
295 (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
296 io_schedule())
297
298
299
300
301#define io_wait_event(wq_head, condition) \
302do { \
303 might_sleep(); \
304 if (condition) \
305 break; \
306 __io_wait_event(wq_head, condition); \
307} while (0)
308
309#define __wait_event_freezable(wq_head, condition) \
310 ___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
311 schedule(); try_to_freeze())
312
313
314
315
316
317
318
319
320
321
322
323
324
325#define wait_event_freezable(wq_head, condition) \
326({ \
327 int __ret = 0; \
328 might_sleep(); \
329 if (!(condition)) \
330 __ret = __wait_event_freezable(wq_head, condition); \
331 __ret; \
332})
333
334#define __wait_event_timeout(wq_head, condition, timeout) \
335 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
336 TASK_UNINTERRUPTIBLE, 0, timeout, \
337 __ret = schedule_timeout(__ret))
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358#define wait_event_timeout(wq_head, condition, timeout) \
359({ \
360 long __ret = timeout; \
361 might_sleep(); \
362 if (!___wait_cond_timeout(condition)) \
363 __ret = __wait_event_timeout(wq_head, condition, timeout); \
364 __ret; \
365})
366
367#define __wait_event_freezable_timeout(wq_head, condition, timeout) \
368 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
369 TASK_INTERRUPTIBLE, 0, timeout, \
370 __ret = schedule_timeout(__ret); try_to_freeze())
371
372
373
374
375
376#define wait_event_freezable_timeout(wq_head, condition, timeout) \
377({ \
378 long __ret = timeout; \
379 might_sleep(); \
380 if (!___wait_cond_timeout(condition)) \
381 __ret = __wait_event_freezable_timeout(wq_head, condition, timeout); \
382 __ret; \
383})
384
385#define __wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2) \
386 (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 1, 0, \
387 cmd1; schedule(); cmd2)
388
389
390
391#define wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2) \
392do { \
393 if (condition) \
394 break; \
395 __wait_event_exclusive_cmd(wq_head, condition, cmd1, cmd2); \
396} while (0)
397
398#define __wait_event_cmd(wq_head, condition, cmd1, cmd2) \
399 (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
400 cmd1; schedule(); cmd2)
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416#define wait_event_cmd(wq_head, condition, cmd1, cmd2) \
417do { \
418 if (condition) \
419 break; \
420 __wait_event_cmd(wq_head, condition, cmd1, cmd2); \
421} while (0)
422
423#define __wait_event_interruptible(wq_head, condition) \
424 ___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
425 schedule())
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442#define wait_event_interruptible(wq_head, condition) \
443({ \
444 int __ret = 0; \
445 might_sleep(); \
446 if (!(condition)) \
447 __ret = __wait_event_interruptible(wq_head, condition); \
448 __ret; \
449})
450
451#define __wait_event_interruptible_timeout(wq_head, condition, timeout) \
452 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
453 TASK_INTERRUPTIBLE, 0, timeout, \
454 __ret = schedule_timeout(__ret))
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476#define wait_event_interruptible_timeout(wq_head, condition, timeout) \
477({ \
478 long __ret = timeout; \
479 might_sleep(); \
480 if (!___wait_cond_timeout(condition)) \
481 __ret = __wait_event_interruptible_timeout(wq_head, \
482 condition, timeout); \
483 __ret; \
484})
485
486#define __wait_event_hrtimeout(wq_head, condition, timeout, state) \
487({ \
488 int __ret = 0; \
489 struct hrtimer_sleeper __t; \
490 \
491 hrtimer_init_on_stack(&__t.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL); \
492 hrtimer_init_sleeper(&__t, current); \
493 if ((timeout) != KTIME_MAX) \
494 hrtimer_start_range_ns(&__t.timer, timeout, \
495 current->timer_slack_ns, \
496 HRTIMER_MODE_REL); \
497 \
498 __ret = ___wait_event(wq_head, condition, state, 0, 0, \
499 if (!__t.task) { \
500 __ret = -ETIME; \
501 break; \
502 } \
503 schedule()); \
504 \
505 hrtimer_cancel(&__t.timer); \
506 destroy_hrtimer_on_stack(&__t.timer); \
507 __ret; \
508})
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526#define wait_event_hrtimeout(wq_head, condition, timeout) \
527({ \
528 int __ret = 0; \
529 might_sleep(); \
530 if (!(condition)) \
531 __ret = __wait_event_hrtimeout(wq_head, condition, timeout, \
532 TASK_UNINTERRUPTIBLE); \
533 __ret; \
534})
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552#define wait_event_interruptible_hrtimeout(wq, condition, timeout) \
553({ \
554 long __ret = 0; \
555 might_sleep(); \
556 if (!(condition)) \
557 __ret = __wait_event_hrtimeout(wq, condition, timeout, \
558 TASK_INTERRUPTIBLE); \
559 __ret; \
560})
561
562#define __wait_event_interruptible_exclusive(wq, condition) \
563 ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
564 schedule())
565
566#define wait_event_interruptible_exclusive(wq, condition) \
567({ \
568 int __ret = 0; \
569 might_sleep(); \
570 if (!(condition)) \
571 __ret = __wait_event_interruptible_exclusive(wq, condition); \
572 __ret; \
573})
574
575#define __wait_event_killable_exclusive(wq, condition) \
576 ___wait_event(wq, condition, TASK_KILLABLE, 1, 0, \
577 schedule())
578
579#define wait_event_killable_exclusive(wq, condition) \
580({ \
581 int __ret = 0; \
582 might_sleep(); \
583 if (!(condition)) \
584 __ret = __wait_event_killable_exclusive(wq, condition); \
585 __ret; \
586})
587
588
589#define __wait_event_freezable_exclusive(wq, condition) \
590 ___wait_event(wq, condition, TASK_INTERRUPTIBLE, 1, 0, \
591 schedule(); try_to_freeze())
592
593#define wait_event_freezable_exclusive(wq, condition) \
594({ \
595 int __ret = 0; \
596 might_sleep(); \
597 if (!(condition)) \
598 __ret = __wait_event_freezable_exclusive(wq, condition); \
599 __ret; \
600})
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615#define wait_event_idle(wq_head, condition) \
616do { \
617 might_sleep(); \
618 if (!(condition)) \
619 ___wait_event(wq_head, condition, TASK_IDLE, 0, 0, schedule()); \
620} while (0)
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639#define wait_event_idle_exclusive(wq_head, condition) \
640do { \
641 might_sleep(); \
642 if (!(condition)) \
643 ___wait_event(wq_head, condition, TASK_IDLE, 1, 0, schedule()); \
644} while (0)
645
646#define __wait_event_idle_timeout(wq_head, condition, timeout) \
647 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
648 TASK_IDLE, 0, timeout, \
649 __ret = schedule_timeout(__ret))
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670#define wait_event_idle_timeout(wq_head, condition, timeout) \
671({ \
672 long __ret = timeout; \
673 might_sleep(); \
674 if (!___wait_cond_timeout(condition)) \
675 __ret = __wait_event_idle_timeout(wq_head, condition, timeout); \
676 __ret; \
677})
678
679#define __wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \
680 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
681 TASK_IDLE, 1, timeout, \
682 __ret = schedule_timeout(__ret))
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707#define wait_event_idle_exclusive_timeout(wq_head, condition, timeout) \
708({ \
709 long __ret = timeout; \
710 might_sleep(); \
711 if (!___wait_cond_timeout(condition)) \
712 __ret = __wait_event_idle_exclusive_timeout(wq_head, condition, timeout);\
713 __ret; \
714})
715
716extern int do_wait_intr(wait_queue_head_t *, wait_queue_entry_t *);
717extern int do_wait_intr_irq(wait_queue_head_t *, wait_queue_entry_t *);
718
719#define __wait_event_interruptible_locked(wq, condition, exclusive, fn) \
720({ \
721 int __ret; \
722 DEFINE_WAIT(__wait); \
723 if (exclusive) \
724 __wait.flags |= WQ_FLAG_EXCLUSIVE; \
725 do { \
726 __ret = fn(&(wq), &__wait); \
727 if (__ret) \
728 break; \
729 } while (!(condition)); \
730 __remove_wait_queue(&(wq), &__wait); \
731 __set_current_state(TASK_RUNNING); \
732 __ret; \
733})
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759#define wait_event_interruptible_locked(wq, condition) \
760 ((condition) \
761 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, do_wait_intr))
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786#define wait_event_interruptible_locked_irq(wq, condition) \
787 ((condition) \
788 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, do_wait_intr_irq))
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817#define wait_event_interruptible_exclusive_locked(wq, condition) \
818 ((condition) \
819 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr))
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848#define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
849 ((condition) \
850 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, do_wait_intr_irq))
851
852
853#define __wait_event_killable(wq, condition) \
854 ___wait_event(wq, condition, TASK_KILLABLE, 0, 0, schedule())
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871#define wait_event_killable(wq_head, condition) \
872({ \
873 int __ret = 0; \
874 might_sleep(); \
875 if (!(condition)) \
876 __ret = __wait_event_killable(wq_head, condition); \
877 __ret; \
878})
879
880#define __wait_event_killable_timeout(wq_head, condition, timeout) \
881 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
882 TASK_KILLABLE, 0, timeout, \
883 __ret = schedule_timeout(__ret))
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907#define wait_event_killable_timeout(wq_head, condition, timeout) \
908({ \
909 long __ret = timeout; \
910 might_sleep(); \
911 if (!___wait_cond_timeout(condition)) \
912 __ret = __wait_event_killable_timeout(wq_head, \
913 condition, timeout); \
914 __ret; \
915})
916
917
918#define __wait_event_lock_irq(wq_head, condition, lock, cmd) \
919 (void)___wait_event(wq_head, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
920 spin_unlock_irq(&lock); \
921 cmd; \
922 schedule(); \
923 spin_lock_irq(&lock))
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948#define wait_event_lock_irq_cmd(wq_head, condition, lock, cmd) \
949do { \
950 if (condition) \
951 break; \
952 __wait_event_lock_irq(wq_head, condition, lock, cmd); \
953} while (0)
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975#define wait_event_lock_irq(wq_head, condition, lock) \
976do { \
977 if (condition) \
978 break; \
979 __wait_event_lock_irq(wq_head, condition, lock, ); \
980} while (0)
981
982
983#define __wait_event_interruptible_lock_irq(wq_head, condition, lock, cmd) \
984 ___wait_event(wq_head, condition, TASK_INTERRUPTIBLE, 0, 0, \
985 spin_unlock_irq(&lock); \
986 cmd; \
987 schedule(); \
988 spin_lock_irq(&lock))
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015#define wait_event_interruptible_lock_irq_cmd(wq_head, condition, lock, cmd) \
1016({ \
1017 int __ret = 0; \
1018 if (!(condition)) \
1019 __ret = __wait_event_interruptible_lock_irq(wq_head, \
1020 condition, lock, cmd); \
1021 __ret; \
1022})
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046#define wait_event_interruptible_lock_irq(wq_head, condition, lock) \
1047({ \
1048 int __ret = 0; \
1049 if (!(condition)) \
1050 __ret = __wait_event_interruptible_lock_irq(wq_head, \
1051 condition, lock,); \
1052 __ret; \
1053})
1054
1055#define __wait_event_interruptible_lock_irq_timeout(wq_head, condition, \
1056 lock, timeout) \
1057 ___wait_event(wq_head, ___wait_cond_timeout(condition), \
1058 TASK_INTERRUPTIBLE, 0, timeout, \
1059 spin_unlock_irq(&lock); \
1060 __ret = schedule_timeout(__ret); \
1061 spin_lock_irq(&lock));
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087#define wait_event_interruptible_lock_irq_timeout(wq_head, condition, lock, \
1088 timeout) \
1089({ \
1090 long __ret = timeout; \
1091 if (!___wait_cond_timeout(condition)) \
1092 __ret = __wait_event_interruptible_lock_irq_timeout( \
1093 wq_head, condition, lock, timeout); \
1094 __ret; \
1095})
1096
1097
1098
1099
1100void prepare_to_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
1101void prepare_to_wait_exclusive(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
1102long prepare_to_wait_event(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry, int state);
1103void finish_wait(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry);
1104long wait_woken(struct wait_queue_entry *wq_entry, unsigned mode, long timeout);
1105int woken_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
1106int autoremove_wake_function(struct wait_queue_entry *wq_entry, unsigned mode, int sync, void *key);
1107
1108#define DEFINE_WAIT_FUNC(name, function) \
1109 struct wait_queue_entry name = { \
1110 .private = current, \
1111 .func = function, \
1112 .entry = LIST_HEAD_INIT((name).entry), \
1113 }
1114
1115#define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
1116
1117#define init_wait(wait) \
1118 do { \
1119 (wait)->private = current; \
1120 (wait)->func = autoremove_wake_function; \
1121 INIT_LIST_HEAD(&(wait)->entry); \
1122 (wait)->flags = 0; \
1123 } while (0)
1124
1125#endif
1126