4 #define WNOHANG 0x00000001
5 #define WUNTRACED 0x00000002
6 #define WSTOPPED WUNTRACED
7 #define WEXITED 0x00000004
8 #define WCONTINUED 0x00000008
9 #define WNOWAIT 0x01000000 /* Don't reap, just poll status. */
11 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */
12 #define __WALL 0x40000000 /* Wait on all children, regardless of type */
13 #define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */
15 /* First argument to waitid: */
22 #include <linux/config.h>
23 #include <linux/list.h>
24 #include <linux/stddef.h>
25 #include <linux/spinlock.h>
26 #include <asm/system.h>
28 typedef struct __wait_queue wait_queue_t
;
29 typedef int (*wait_queue_func_t
)(wait_queue_t
*wait
, unsigned mode
, int sync
, void *key
);
30 int default_wake_function(wait_queue_t
*wait
, unsigned mode
, int sync
, void *key
);
34 #define WQ_FLAG_EXCLUSIVE 0x01
35 struct task_struct
* task
;
36 wait_queue_func_t func
;
37 struct list_head task_list
;
40 struct __wait_queue_head
{
42 struct list_head task_list
;
44 typedef struct __wait_queue_head wait_queue_head_t
;
48 * Macros for declaration and initialisaton of the datatypes
51 #define __WAITQUEUE_INITIALIZER(name, tsk) { \
53 .func = default_wake_function, \
54 .task_list = { NULL, NULL } }
56 #define DECLARE_WAITQUEUE(name, tsk) \
57 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
59 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
60 .lock = SPIN_LOCK_UNLOCKED, \
61 .task_list = { &(name).task_list, &(name).task_list } }
63 #define DECLARE_WAIT_QUEUE_HEAD(name) \
64 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
66 static inline void init_waitqueue_head(wait_queue_head_t
*q
)
68 q
->lock
= SPIN_LOCK_UNLOCKED
;
69 INIT_LIST_HEAD(&q
->task_list
);
72 static inline void init_waitqueue_entry(wait_queue_t
*q
, struct task_struct
*p
)
76 q
->func
= default_wake_function
;
79 static inline void init_waitqueue_func_entry(wait_queue_t
*q
,
80 wait_queue_func_t func
)
87 static inline int waitqueue_active(wait_queue_head_t
*q
)
89 return !list_empty(&q
->task_list
);
93 * Used to distinguish between sync and async io wait context:
94 * sync i/o typically specifies a NULL wait queue entry or a wait
95 * queue entry bound to a task (current task) to wake up.
96 * aio specifies a wait queue entry with an async notification
97 * callback routine, not associated with any task.
99 #define is_sync_wait(wait) (!(wait) || ((wait)->task))
101 extern void FASTCALL(add_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
102 extern void FASTCALL(add_wait_queue_exclusive(wait_queue_head_t
*q
, wait_queue_t
* wait
));
103 extern void FASTCALL(remove_wait_queue(wait_queue_head_t
*q
, wait_queue_t
* wait
));
105 static inline void __add_wait_queue(wait_queue_head_t
*head
, wait_queue_t
*new)
107 list_add(&new->task_list
, &head
->task_list
);
111 * Used for wake-one threads:
113 static inline void __add_wait_queue_tail(wait_queue_head_t
*head
,
116 list_add_tail(&new->task_list
, &head
->task_list
);
119 static inline void __remove_wait_queue(wait_queue_head_t
*head
,
122 list_del(&old
->task_list
);
125 void FASTCALL(__wake_up(wait_queue_head_t
*q
, unsigned int mode
, int nr
, void *key
));
126 extern void FASTCALL(__wake_up_locked(wait_queue_head_t
*q
, unsigned int mode
));
127 extern void FASTCALL(__wake_up_sync(wait_queue_head_t
*q
, unsigned int mode
, int nr
));
129 #define wake_up(x) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 1, NULL)
130 #define wake_up_nr(x, nr) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, nr, NULL)
131 #define wake_up_all(x) __wake_up(x, TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0, NULL)
132 #define wake_up_all_sync(x) __wake_up_sync((x),TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE, 0)
133 #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
134 #define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
135 #define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
136 #define wake_up_locked(x) __wake_up_locked((x), TASK_UNINTERRUPTIBLE | TASK_INTERRUPTIBLE)
137 #define wake_up_interruptible_sync(x) __wake_up_sync((x),TASK_INTERRUPTIBLE, 1)
139 #define __wait_event(wq, condition) \
141 DEFINE_WAIT(__wait); \
144 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
149 finish_wait(&wq, &__wait); \
152 #define wait_event(wq, condition) \
156 __wait_event(wq, condition); \
159 #define __wait_event_timeout(wq, condition, ret) \
161 DEFINE_WAIT(__wait); \
164 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
167 ret = schedule_timeout(ret); \
171 finish_wait(&wq, &__wait); \
174 #define wait_event_timeout(wq, condition, timeout) \
176 long __ret = timeout; \
178 __wait_event_timeout(wq, condition, __ret); \
182 #define __wait_event_interruptible(wq, condition, ret) \
184 DEFINE_WAIT(__wait); \
187 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
190 if (!signal_pending(current)) { \
194 ret = -ERESTARTSYS; \
197 finish_wait(&wq, &__wait); \
200 #define wait_event_interruptible(wq, condition) \
204 __wait_event_interruptible(wq, condition, __ret); \
208 #define __wait_event_interruptible_timeout(wq, condition, ret) \
210 DEFINE_WAIT(__wait); \
213 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
216 if (!signal_pending(current)) { \
217 ret = schedule_timeout(ret); \
222 ret = -ERESTARTSYS; \
225 finish_wait(&wq, &__wait); \
228 #define wait_event_interruptible_timeout(wq, condition, timeout) \
230 long __ret = timeout; \
232 __wait_event_interruptible_timeout(wq, condition, __ret); \
236 #define __wait_event_interruptible_exclusive(wq, condition, ret) \
238 DEFINE_WAIT(__wait); \
241 prepare_to_wait_exclusive(&wq, &__wait, \
242 TASK_INTERRUPTIBLE); \
245 if (!signal_pending(current)) { \
249 ret = -ERESTARTSYS; \
252 finish_wait(&wq, &__wait); \
255 #define wait_event_interruptible_exclusive(wq, condition) \
259 __wait_event_interruptible_exclusive(wq, condition, __ret);\
264 * Must be called with the spinlock in the wait_queue_head_t held.
266 static inline void add_wait_queue_exclusive_locked(wait_queue_head_t
*q
,
269 wait
->flags
|= WQ_FLAG_EXCLUSIVE
;
270 __add_wait_queue_tail(q
, wait
);
274 * Must be called with the spinlock in the wait_queue_head_t held.
276 static inline void remove_wait_queue_locked(wait_queue_head_t
*q
,
279 __remove_wait_queue(q
, wait
);
283 * These are the old interfaces to sleep waiting for an event.
284 * They are racy. DO NOT use them, use the wait_event* interfaces above.
285 * We plan to remove these interfaces during 2.7.
287 extern void FASTCALL(sleep_on(wait_queue_head_t
*q
));
288 extern long FASTCALL(sleep_on_timeout(wait_queue_head_t
*q
,
289 signed long timeout
));
290 extern void FASTCALL(interruptible_sleep_on(wait_queue_head_t
*q
));
291 extern long FASTCALL(interruptible_sleep_on_timeout(wait_queue_head_t
*q
,
292 signed long timeout
));
295 * Waitqueues which are removed from the waitqueue_head at wakeup time
297 void FASTCALL(prepare_to_wait(wait_queue_head_t
*q
,
298 wait_queue_t
*wait
, int state
));
299 void FASTCALL(prepare_to_wait_exclusive(wait_queue_head_t
*q
,
300 wait_queue_t
*wait
, int state
));
301 void FASTCALL(finish_wait(wait_queue_head_t
*q
, wait_queue_t
*wait
));
302 int autoremove_wake_function(wait_queue_t
*wait
, unsigned mode
, int sync
, void *key
);
304 #define DEFINE_WAIT(name) \
305 wait_queue_t name = { \
307 .func = autoremove_wake_function, \
308 .task_list = { .next = &name.task_list, \
309 .prev = &name.task_list, \
313 #define init_wait(wait) \
315 wait->task = current; \
316 wait->func = autoremove_wake_function; \
317 INIT_LIST_HEAD(&wait->task_list); \
320 #endif /* __KERNEL__ */