4 #define WNOHANG 0x00000001
5 #define WUNTRACED 0x00000002
7 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */
8 #define __WALL 0x40000000 /* Wait on all children, regardless of type */
9 #define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */
13 #include <linux/config.h>
14 #include <linux/list.h>
15 #include <linux/stddef.h>
16 #include <linux/spinlock.h>
17 #include <asm/system.h>
19 typedef struct __wait_queue wait_queue_t;
20 typedef int (*wait_queue_func_t)(wait_queue_t *wait, unsigned mode, int sync, void *key);
21 int default_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
25 #define WQ_FLAG_EXCLUSIVE 0x01
26 struct task_struct * task;
27 wait_queue_func_t func;
28 struct list_head task_list;
31 struct __wait_queue_head {
33 struct list_head task_list;
35 typedef struct __wait_queue_head wait_queue_head_t;
39 * Macros for declaration and initialisaton of the datatypes
42 #define __WAITQUEUE_INITIALIZER(name, tsk) { \
44 .func = default_wake_function, \
45 .task_list = { NULL, NULL } }
47 #define DECLARE_WAITQUEUE(name, tsk) \
48 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
50 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
51 .lock = SPIN_LOCK_UNLOCKED, \
52 .task_list = { &(name).task_list, &(name).task_list } }
54 #define DECLARE_WAIT_QUEUE_HEAD(name) \
55 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
57 static inline void init_waitqueue_head(wait_queue_head_t *q)
59 q->lock = SPIN_LOCK_UNLOCKED;
60 INIT_LIST_HEAD(&q->task_list);
63 static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
67 q->func = default_wake_function;
70 static inline void init_waitqueue_func_entry(wait_queue_t *q,
71 wait_queue_func_t func)
78 static inline int waitqueue_active(wait_queue_head_t *q)
80 return !list_empty(&q->task_list);
83 extern void FASTCALL(add_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
84 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t *q, wait_queue_t * wait));
85 extern void FASTCALL(remove_wait_queue(wait_queue_head_t *q, wait_queue_t * wait));
87 static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
89 list_add(&new->task_list, &head->task_list);
93 * Used for wake-one threads:
95 static inline void __add_wait_queue_tail(wait_queue_head_t *head,
98 list_add_tail(&new->task_list, &head->task_list);
101 static inline void __remove_wait_queue(wait_queue_head_t *head,
104 list_del(&old->task_list);
107 void FASTCALL(__wake_up(wait_queue_head_t *q, unsigned int mode, int nr, void *key));
108 extern void FASTCALL(__wake_up_locked(wait_queue_head_t *q, unsigned int mode));
109 extern void FASTCALL(__wake_up_sync(wait_queue_head_t *q, unsigned int mode, int nr));
111 #define wake_up(x) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, NULL)
112 #define wake_up_nr(x, nr) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr, NULL)
113 #define wake_up_all(x) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0, NULL)
114 #define wake_up_all_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0)
115 #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
116 #define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
117 #define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
118 #define wake_up_locked(x) __wake_up_locked((x), TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
119 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE, 1)
121 #define __wait_event(wq, condition) \
123 DEFINE_WAIT(__wait); \
126 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
131 finish_wait(&wq, &__wait); \
134 #define wait_event(wq, condition) \
138 __wait_event(wq, condition); \
141 #define __wait_event_interruptible(wq, condition, ret) \
143 DEFINE_WAIT(__wait); \
146 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
149 if (!signal_pending(current)) { \
153 ret = -ERESTARTSYS; \
156 finish_wait(&wq, &__wait); \
159 #define wait_event_interruptible(wq, condition) \
163 __wait_event_interruptible(wq, condition, __ret); \
167 #define __wait_event_interruptible_timeout(wq, condition, ret) \
169 DEFINE_WAIT(__wait); \
172 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
175 if (!signal_pending(current)) { \
176 ret = schedule_timeout(ret); \
181 ret = -ERESTARTSYS; \
184 finish_wait(&wq, &__wait); \
187 #define wait_event_interruptible_timeout(wq, condition, timeout) \
189 long __ret = timeout; \
191 __wait_event_interruptible_timeout(wq, condition, __ret); \
195 #define __wait_event_interruptible_exclusive(wq, condition, ret) \
197 DEFINE_WAIT(__wait); \
200 prepare_to_wait_exclusive(&wq, &__wait, \
201 TASK_INTERRUPTIBLE); \
204 if (!signal_pending(current)) { \
208 ret = -ERESTARTSYS; \
211 finish_wait(&wq, &__wait); \
214 #define wait_event_interruptible_exclusive(wq, condition) \
218 __wait_event_interruptible_exclusive(wq, condition, __ret);\
223 * Must be called with the spinlock in the wait_queue_head_t held.
225 static inline void add_wait_queue_exclusive_locked(wait_queue_head_t *q,
228 wait->flags |= WQ_FLAG_EXCLUSIVE;
229 __add_wait_queue_tail(q, wait);
233 * Must be called with the spinlock in the wait_queue_head_t held.
235 static inline void remove_wait_queue_locked(wait_queue_head_t *q,
238 __remove_wait_queue(q, wait);
242 * These are the old interfaces to sleep waiting for an event.
243 * They are racy. DO NOT use them, use the wait_event* interfaces above.
244 * We plan to remove these interfaces during 2.7.
246 extern void FASTCALL(sleep_on(wait_queue_head_t *q));
247 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t *q,
248 signed long timeout));
249 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t *q));
250 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t *q,
251 signed long timeout));
254 * Waitqueues which are removed from the waitqueue_head at wakeup time
256 void FASTCALL(prepare_to_wait(wait_queue_head_t *q,
257 wait_queue_t *wait, int state));
258 void FASTCALL(prepare_to_wait_exclusive(wait_queue_head_t *q,
259 wait_queue_t *wait, int state));
260 void FASTCALL(finish_wait(wait_queue_head_t *q, wait_queue_t *wait));
261 int autoremove_wake_function(wait_queue_t *wait, unsigned mode, int sync, void *key);
263 #define DEFINE_WAIT(name) \
264 wait_queue_t name = { \
266 .func = autoremove_wake_function, \
267 .task_list = { .next = &name.task_list, \
268 .prev = &name.task_list, \
272 #define init_wait(wait) \
274 wait->task = current; \
275 wait->func = autoremove_wake_function; \
276 INIT_LIST_HEAD(&wait->task_list); \
279 #endif /* __KERNEL__ */