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;
23 struct list_head task_list;
26 void wake_up(wait_queue_head_t *);
27 void prepare_to_wait(wait_queue_head_t *q, wait_queue_t *wait, int state);
28 void finish_wait(wait_queue_head_t *q, wait_queue_t *wait);
29 int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
30 int default_wake_function(wait_queue_t *wait, unsigned mode, int flags, void *key);
32 #define DECLARE_WAITQUEUE(name, tsk) \
33 wait_queue_t name = { \
35 .func = default_wake_function, \
36 .task_list = { NULL, NULL } \
39 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
40 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
41 .task_list = { &(name).task_list, &(name).task_list } }
43 #define DECLARE_WAIT_QUEUE_HEAD(name) \
44 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
46 static inline void init_waitqueue_head(wait_queue_head_t *q)
48 spin_lock_init(&q->lock);
49 INIT_LIST_HEAD(&q->task_list);
52 #define DEFINE_WAIT(name) \
53 wait_queue_t name = { \
55 .func = autoremove_wake_function, \
56 .task_list = LIST_HEAD_INIT((name).task_list), \
59 #define ___wait_cond_timeout(condition) \
61 bool __cond = (condition); \
62 if (__cond && !__ret) \
67 #define ___wait_event(wq, condition, state, exclusive, ret, cmd) \
69 DEFINE_WAIT(__wait); \
73 prepare_to_wait(&wq, &__wait, state); \
78 finish_wait(&wq, &__wait); \
82 #define __wait_event(wq, condition) \
83 (void)___wait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, 0, \
86 #define wait_event(wq, condition) \
90 __wait_event(wq, condition); \
93 #define wait_event_freezable(wq, condition) ({wait_event(wq, condition); 0; })
94 #define wait_event_killable(wq, condition) ({wait_event(wq, condition); 0; })
95 #define wait_event_interruptible(wq, condition) ({wait_event(wq, condition); 0; })
97 #define __wait_event_timeout(wq, condition, timeout) \
98 ___wait_event(wq, ___wait_cond_timeout(condition), \
99 TASK_UNINTERRUPTIBLE, 0, timeout, \
100 __ret = schedule_timeout(__ret))
102 #define wait_event_timeout(wq, condition, timeout) \
104 long __ret = timeout; \
105 if (!___wait_cond_timeout(condition)) \
106 __ret = __wait_event_timeout(wq, condition, timeout); \
110 void wake_up_bit(void *, int);
111 void __wait_on_bit(void *, int, unsigned);
112 void __wait_on_bit_lock(void *, int, unsigned);
115 wait_on_bit(unsigned long *word, int bit, unsigned mode)
117 if (!test_bit(bit, word))
119 __wait_on_bit(word, bit, mode);
124 wait_on_bit_lock(unsigned long *word, int bit, unsigned mode)
126 if (!test_and_set_bit(bit, word))
128 __wait_on_bit_lock(word, bit, mode);
132 #define wait_on_bit_io(w, b, m) wait_on_bit(w, b, m)
133 #define wait_on_bit_lock_io(w, b, m) wait_on_bit_lock(w, b, m)
135 #endif /* _LINUX_WAIT_H */