5 #include <linux/list.h>
6 #include <linux/stddef.h>
8 #include <asm/current.h>
17 #define WQ_FLAG_EXCLUSIVE 0x01
45 #define __WAITQUEUE_INITIALIZER(name, tsk) { \
47 .func = default_wake_function, \
48 .task_list = { NULL, NULL } }
50 #define DECLARE_WAITQUEUE(name, tsk) \
51 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
53 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
54 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
55 .task_list = { &(name).task_list, &(name).task_list } }
57 #define DECLARE_WAIT_QUEUE_HEAD(name) \
58 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
60 #define __WAIT_BIT_KEY_INITIALIZER(word, bit) \
61 { .flags = word, .bit_nr = bit, }
65 #define init_waitqueue_head(q) \
67 static struct lock_class_key __key; \
69 __init_waitqueue_head((q), #q, &__key); \
73 # define __WAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
74 ({ init_waitqueue_head(&name); name; })
75 # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) \
76 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INIT_ONSTACK(name)
78 # define DECLARE_WAIT_QUEUE_HEAD_ONSTACK(name) DECLARE_WAIT_QUEUE_HEAD(name)
107 list_add(&new->task_list, &head->
task_list);
117 __add_wait_queue(q, wait);
130 __add_wait_queue_tail(q, wait);
153 #define wake_up(x) __wake_up(x, TASK_NORMAL, 1, NULL)
154 #define wake_up_nr(x, nr) __wake_up(x, TASK_NORMAL, nr, NULL)
155 #define wake_up_all(x) __wake_up(x, TASK_NORMAL, 0, NULL)
156 #define wake_up_locked(x) __wake_up_locked((x), TASK_NORMAL, 1)
157 #define wake_up_all_locked(x) __wake_up_locked((x), TASK_NORMAL, 0)
159 #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL)
160 #define wake_up_interruptible_nr(x, nr) __wake_up(x, TASK_INTERRUPTIBLE, nr, NULL)
161 #define wake_up_interruptible_all(x) __wake_up(x, TASK_INTERRUPTIBLE, 0, NULL)
162 #define wake_up_interruptible_sync(x) __wake_up_sync((x), TASK_INTERRUPTIBLE, 1)
167 #define wake_up_poll(x, m) \
168 __wake_up(x, TASK_NORMAL, 1, (void *) (m))
169 #define wake_up_locked_poll(x, m) \
170 __wake_up_locked_key((x), TASK_NORMAL, (void *) (m))
171 #define wake_up_interruptible_poll(x, m) \
172 __wake_up(x, TASK_INTERRUPTIBLE, 1, (void *) (m))
173 #define wake_up_interruptible_sync_poll(x, m) \
174 __wake_up_sync_key((x), TASK_INTERRUPTIBLE, 1, (void *) (m))
176 #define __wait_event(wq, condition) \
178 DEFINE_WAIT(__wait); \
181 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
186 finish_wait(&wq, &__wait); \
201 #define wait_event(wq, condition) \
205 __wait_event(wq, condition); \
208 #define __wait_event_timeout(wq, condition, ret) \
210 DEFINE_WAIT(__wait); \
213 prepare_to_wait(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
216 ret = schedule_timeout(ret); \
220 finish_wait(&wq, &__wait); \
239 #define wait_event_timeout(wq, condition, timeout) \
241 long __ret = timeout; \
243 __wait_event_timeout(wq, condition, __ret); \
247 #define __wait_event_interruptible(wq, condition, ret) \
249 DEFINE_WAIT(__wait); \
252 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
255 if (!signal_pending(current)) { \
259 ret = -ERESTARTSYS; \
262 finish_wait(&wq, &__wait); \
280 #define wait_event_interruptible(wq, condition) \
284 __wait_event_interruptible(wq, condition, __ret); \
288 #define __wait_event_interruptible_timeout(wq, condition, ret) \
290 DEFINE_WAIT(__wait); \
293 prepare_to_wait(&wq, &__wait, TASK_INTERRUPTIBLE); \
296 if (!signal_pending(current)) { \
297 ret = schedule_timeout(ret); \
302 ret = -ERESTARTSYS; \
305 finish_wait(&wq, &__wait); \
325 #define wait_event_interruptible_timeout(wq, condition, timeout) \
327 long __ret = timeout; \
329 __wait_event_interruptible_timeout(wq, condition, __ret); \
333 #define __wait_event_interruptible_exclusive(wq, condition, ret) \
335 DEFINE_WAIT(__wait); \
338 prepare_to_wait_exclusive(&wq, &__wait, \
339 TASK_INTERRUPTIBLE); \
341 finish_wait(&wq, &__wait); \
344 if (!signal_pending(current)) { \
348 ret = -ERESTARTSYS; \
349 abort_exclusive_wait(&wq, &__wait, \
350 TASK_INTERRUPTIBLE, NULL); \
355 #define wait_event_interruptible_exclusive(wq, condition) \
359 __wait_event_interruptible_exclusive(wq, condition, __ret);\
364 #define __wait_event_interruptible_locked(wq, condition, exclusive, irq) \
367 DEFINE_WAIT(__wait); \
369 __wait.flags |= WQ_FLAG_EXCLUSIVE; \
371 if (likely(list_empty(&__wait.task_list))) \
372 __add_wait_queue_tail(&(wq), &__wait); \
373 set_current_state(TASK_INTERRUPTIBLE); \
374 if (signal_pending(current)) { \
375 __ret = -ERESTARTSYS; \
379 spin_unlock_irq(&(wq).lock); \
381 spin_unlock(&(wq).lock); \
384 spin_lock_irq(&(wq).lock); \
386 spin_lock(&(wq).lock); \
387 } while (!(condition)); \
388 __remove_wait_queue(&(wq), &__wait); \
389 __set_current_state(TASK_RUNNING); \
417 #define wait_event_interruptible_locked(wq, condition) \
419 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 0))
444 #define wait_event_interruptible_locked_irq(wq, condition) \
446 ? 0 : __wait_event_interruptible_locked(wq, condition, 0, 1))
475 #define wait_event_interruptible_exclusive_locked(wq, condition) \
477 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 0))
506 #define wait_event_interruptible_exclusive_locked_irq(wq, condition) \
508 ? 0 : __wait_event_interruptible_locked(wq, condition, 1, 1))
512 #define __wait_event_killable(wq, condition, ret) \
514 DEFINE_WAIT(__wait); \
517 prepare_to_wait(&wq, &__wait, TASK_KILLABLE); \
520 if (!fatal_signal_pending(current)) { \
524 ret = -ERESTARTSYS; \
527 finish_wait(&wq, &__wait); \
545 #define wait_event_killable(wq, condition) \
549 __wait_event_killable(wq, condition, __ret); \
560 signed long timeout);
563 signed long timeout);
576 #define DEFINE_WAIT_FUNC(name, function) \
577 wait_queue_t name = { \
578 .private = current, \
580 .task_list = LIST_HEAD_INIT((name).task_list), \
583 #define DEFINE_WAIT(name) DEFINE_WAIT_FUNC(name, autoremove_wake_function)
585 #define DEFINE_WAIT_BIT(name, word, bit) \
586 struct wait_bit_queue name = { \
587 .key = __WAIT_BIT_KEY_INITIALIZER(word, bit), \
589 .private = current, \
590 .func = wake_bit_function, \
592 LIST_HEAD_INIT((name).wait.task_list), \
596 #define init_wait(wait) \
598 (wait)->private = current; \
599 (wait)->func = autoremove_wake_function; \
600 INIT_LIST_HEAD(&(wait)->task_list); \
618 static inline int wait_on_bit(
void *
word,
int bit,
642 static inline int wait_on_bit_lock(
void *word,
int bit,