1 #ifndef _LINUX_WAIT_SIMPLE_H
2 #define _LINUX_WAIT_SIMPLE_H
4 #include <linux/spinlock.h>
5 #include <linux/list.h>
7 #include <asm/current.h>
10 struct task_struct *task;
11 struct list_head node;
14 #define DEFINE_SWAITER(name) \
15 struct swaiter name = { \
17 .node = LIST_HEAD_INIT((name).node), \
22 struct list_head list;
25 #define SWAIT_HEAD_INITIALIZER(name) { \
26 .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
27 .list = LIST_HEAD_INIT((name).list), \
30 #define DEFINE_SWAIT_HEAD(name) \
31 struct swait_head name = SWAIT_HEAD_INITIALIZER(name)
33 extern void __init_swait_head(struct swait_head *h, struct lock_class_key *key);
35 #define init_swait_head(swh) \
37 static struct lock_class_key __key; \
39 __init_swait_head((swh), &__key); \
45 extern void swait_prepare_locked(struct swait_head *head, struct swaiter *w);
46 extern void swait_prepare(struct swait_head *head, struct swaiter *w, int state);
47 extern void swait_finish_locked(struct swait_head *head, struct swaiter *w);
48 extern void swait_finish(struct swait_head *head, struct swaiter *w);
50 /* Check whether a head has waiters enqueued */
51 static inline bool swaitqueue_active(struct swait_head *h)
53 /* Make sure the condition is visible before checking list_empty() */
55 return !list_empty(&h->list);
61 extern unsigned int __swait_wake(struct swait_head *head, unsigned int state, unsigned int num);
62 extern unsigned int __swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num);
64 #define swait_wake(head) __swait_wake(head, TASK_NORMAL, 1)
65 #define swait_wake_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 1)
66 #define swait_wake_all(head) __swait_wake(head, TASK_NORMAL, 0)
67 #define swait_wake_all_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 0)
72 #define __swait_event(wq, condition) \
74 DEFINE_SWAITER(__wait); \
77 swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
82 swait_finish(&wq, &__wait); \
86 * swait_event - sleep until a condition gets true
87 * @wq: the waitqueue to wait on
88 * @condition: a C expression for the event to wait for
90 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
91 * @condition evaluates to true. The @condition is checked each time
92 * the waitqueue @wq is woken up.
94 * wake_up() has to be called after changing any variable that could
95 * change the result of the wait condition.
97 #define swait_event(wq, condition) \
101 __swait_event(wq, condition); \
104 #define __swait_event_interruptible(wq, condition, ret) \
106 DEFINE_SWAITER(__wait); \
109 swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
112 if (signal_pending(current)) { \
113 ret = -ERESTARTSYS; \
118 swait_finish(&wq, &__wait); \
121 #define __swait_event_interruptible_timeout(wq, condition, ret) \
123 DEFINE_SWAITER(__wait); \
126 swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
129 if (signal_pending(current)) { \
130 ret = -ERESTARTSYS; \
133 ret = schedule_timeout(ret); \
137 swait_finish(&wq, &__wait); \
141 * swait_event_interruptible - sleep until a condition gets true
142 * @wq: the waitqueue to wait on
143 * @condition: a C expression for the event to wait for
145 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
146 * @condition evaluates to true. The @condition is checked each time
147 * the waitqueue @wq is woken up.
149 * wake_up() has to be called after changing any variable that could
150 * change the result of the wait condition.
152 #define swait_event_interruptible(wq, condition) \
156 __swait_event_interruptible(wq, condition, __ret); \
160 #define swait_event_interruptible_timeout(wq, condition, timeout) \
162 int __ret = timeout; \
164 __swait_event_interruptible_timeout(wq, condition, __ret); \
168 #define __swait_event_timeout(wq, condition, ret) \
170 DEFINE_SWAITER(__wait); \
173 swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
176 ret = schedule_timeout(ret); \
180 swait_finish(&wq, &__wait); \
184 * swait_event_timeout - sleep until a condition gets true or a timeout elapses
185 * @wq: the waitqueue to wait on
186 * @condition: a C expression for the event to wait for
187 * @timeout: timeout, in jiffies
189 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
190 * @condition evaluates to true. The @condition is checked each time
191 * the waitqueue @wq is woken up.
193 * wake_up() has to be called after changing any variable that could
194 * change the result of the wait condition.
196 * The function returns 0 if the @timeout elapsed, and the remaining
197 * jiffies if the condition evaluated to true before the timeout elapsed.
199 #define swait_event_timeout(wq, condition, timeout) \
201 long __ret = timeout; \
203 __swait_event_timeout(wq, condition, __ret); \