5 #include <linux/bitmap.h>
6 #include <linux/list.h>
7 #include <linux/spinlock.h>
9 typedef struct __wait_queue wait_queue_t;
10 typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int flags, void *key);
12 #define WQ_FLAG_EXCLUSIVE 0x01
17 wait_queue_func_t func;
18 struct list_head task_list;
21 struct wait_queue_head {
23 struct list_head task_list;
26 typedef struct wait_queue_head wait_queue_head_t;
28 void wake_up(wait_queue_head_t *);
29 void wake_up_all(wait_queue_head_t *);
30 void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
31 void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
32 int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
33 int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
35 #define DECLARE_WAITQUEUE(name, tsk) \
36 wait_queue_t name = { \
38 .func = default_wake_function, \
39 .task_list = { NULL, NULL } \
42 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
43 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
44 .task_list = { &(name).task_list, &(name).task_list } }
46 #define DECLARE_WAIT_QUEUE_HEAD(name) \
47 struct wait_queue_head name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
49 static inline void init_waitqueue_head(wait_queue_head_t *q)
51 spin_lock_init(&q->lock);
52 INIT_LIST_HEAD(&q->task_list);
55 #define DEFINE_WAIT(name) \
56 wait_queue_t name = { \
58 .func = autoremove_wake_function, \
59 .task_list = LIST_HEAD_INIT((name).task_list), \
62 #define ___wait_cond_timeout(condition) \
64 bool __cond = (condition); \
65 if (__cond && !__ret) \
70 #define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
72 DEFINE_WAIT(__wait); \
76 prepare_to_wait(&wq, &__wait, state); \
81 finish_wait(&wq, &__wait); \
85 #define __wait_event(wq, condition) \
86 (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
89 #define wait_event(wq, condition) \
93 __wait_event(wq, condition); \
96 #define wait_event_freezable(wq, condition) ({wait_event(wq, condition); 0; })
97 #define wait_event_killable(wq, condition) ({wait_event(wq, condition); 0; })
98 #define wait_event_interruptible(wq, condition) ({wait_event(wq, condition); 0; })
100 #define __wait_event_timeout(wq, condition, timeout) \
101 ___wait_event(wq, ___wait_cond_timeout(condition), \
102 TASK_UNINTERRUPTIBLE, 0, timeout, \
103 __ret = schedule_timeout(__ret))
105 #define wait_event_timeout(wq, condition, timeout) \
107 long __ret = timeout; \
108 if (!___wait_cond_timeout(condition)) \
109 __ret = __wait_event_timeout(wq, condition, timeout); \
113 void wake_up_bit(void *, int);
114 void __wait_on_bit(void *, int, unsigned);
115 void __wait_on_bit_lock(void *, int, unsigned);
118 wait_on_bit(unsigned long *word, int bit, unsigned mode)
120 if (!test_bit(bit, word))
122 __wait_on_bit(word, bit, mode);
127 wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
129 if (!test_and_set_bit(bit, word))
131 __wait_on_bit_lock(word, bit, mode);
135 #define wait_on_bit_io(w, b, m) wait_on_bit(w, b, m)
136 #define wait_on_bit_lock_io(w, b, m) wait_on_bit_lock(w, b, m)
138 #endif /* _LINUX_WAIT_H */