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);
53 extern unsigned int __swait_wake(struct swait_head *head, unsigned int state, unsigned int num);
54 extern unsigned int __swait_wake_locked(struct swait_head *head, unsigned int state, unsigned int num);
56 #define swait_wake(head) __swait_wake(head, TASK_NORMAL, 1)
57 #define swait_wake_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 1)
58 #define swait_wake_all(head) __swait_wake(head, TASK_NORMAL, 0)
59 #define swait_wake_all_interruptible(head) __swait_wake(head, TASK_INTERRUPTIBLE, 0)
64 #define __swait_event(wq, condition) \
66 DEFINE_SWAITER(__wait); \
69 swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
74 swait_finish(&wq, &__wait); \
78 * swait_event - sleep until a condition gets true
79 * @wq: the waitqueue to wait on
80 * @condition: a C expression for the event to wait for
82 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
83 * @condition evaluates to true. The @condition is checked each time
84 * the waitqueue @wq is woken up.
86 * wake_up() has to be called after changing any variable that could
87 * change the result of the wait condition.
89 #define swait_event(wq, condition) \
93 __swait_event(wq, condition); \
96 #define __swait_event_interruptible(wq, condition, ret) \
98 DEFINE_SWAITER(__wait); \
101 swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
104 if (signal_pending(current)) { \
105 ret = -ERESTARTSYS; \
110 swait_finish(&wq, &__wait); \
113 #define __swait_event_interruptible_timeout(wq, condition, ret) \
115 DEFINE_SWAITER(__wait); \
118 swait_prepare(&wq, &__wait, TASK_INTERRUPTIBLE); \
121 if (signal_pending(current)) { \
122 ret = -ERESTARTSYS; \
125 ret = schedule_timeout(ret); \
129 swait_finish(&wq, &__wait); \
133 * swait_event_interruptible - sleep until a condition gets true
134 * @wq: the waitqueue to wait on
135 * @condition: a C expression for the event to wait for
137 * The process is put to sleep (TASK_INTERRUPTIBLE) until the
138 * @condition evaluates to true. The @condition is checked each time
139 * the waitqueue @wq is woken up.
141 * wake_up() has to be called after changing any variable that could
142 * change the result of the wait condition.
144 #define swait_event_interruptible(wq, condition) \
148 __swait_event_interruptible(wq, condition, __ret); \
152 #define swait_event_interruptible_timeout(wq, condition, timeout) \
154 int __ret = timeout; \
156 __swait_event_interruptible_timeout(wq, condition, __ret); \
160 #define __swait_event_timeout(wq, condition, ret) \
162 DEFINE_SWAITER(__wait); \
165 swait_prepare(&wq, &__wait, TASK_UNINTERRUPTIBLE); \
168 ret = schedule_timeout(ret); \
172 swait_finish(&wq, &__wait); \
176 * swait_event_timeout - sleep until a condition gets true or a timeout elapses
177 * @wq: the waitqueue to wait on
178 * @condition: a C expression for the event to wait for
179 * @timeout: timeout, in jiffies
181 * The process is put to sleep (TASK_UNINTERRUPTIBLE) until the
182 * @condition evaluates to true. The @condition is checked each time
183 * the waitqueue @wq is woken up.
185 * wake_up() has to be called after changing any variable that could
186 * change the result of the wait condition.
188 * The function returns 0 if the @timeout elapsed, and the remaining
189 * jiffies if the condition evaluated to true before the timeout elapsed.
191 #define swait_event_timeout(wq, condition, timeout) \
193 long __ret = timeout; \
195 __swait_event_timeout(wq, condition, __ret); \