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