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