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