4 #include <linux/list.h>
5 #include <linux/stddef.h>
6 #include <linux/spinlock.h>
7 #include <asm/current.h>
12 * While these are very similar to the other/complex wait queues (wait.h) the
13 * most important difference is that the simple waitqueue allows for
14 * deterministic behaviour -- IOW it has strictly bounded IRQ and lock hold
17 * In order to make this so, we had to drop a fair number of features of the
18 * other waitqueue code; notably:
20 * - mixing INTERRUPTIBLE and UNINTERRUPTIBLE sleeps on the same waitqueue;
21 * all wakeups are TASK_NORMAL in order to avoid O(n) lookups for the right
24 * - the exclusive mode; because this requires preserving the list order
27 * - custom wake functions; because you cannot give any guarantees about
30 * As a side effect of this; the data structures are slimmer.
32 * One would recommend using this wait queue where possible.
37 struct swait_queue_head {
39 struct list_head task_list;
43 struct task_struct *task;
44 struct list_head task_list;
47 #define __SWAITQUEUE_INITIALIZER(name) { \
49 .task_list = LIST_HEAD_INIT((name).task_list), \
52 #define DECLARE_SWAITQUEUE(name) \
53 struct swait_queue name = __SWAITQUEUE_INITIALIZER(name)
55 #define __SWAIT_QUEUE_HEAD_INITIALIZER(name) { \
56 .lock = __RAW_SPIN_LOCK_UNLOCKED(name.lock), \
57 .task_list = LIST_HEAD_INIT((name).task_list), \
60 #define DECLARE_SWAIT_QUEUE_HEAD(name) \
61 struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INITIALIZER(name)
63 extern void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
64 struct lock_class_key *key);
66 #define init_swait_queue_head(q) \
68 static struct lock_class_key __key; \
69 __init_swait_queue_head((q), #q, &__key); \
73 # define __SWAIT_QUEUE_HEAD_INIT_ONSTACK(name) \
74 ({ init_swait_queue_head(&name); name; })
75 # define DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(name) \
76 struct swait_queue_head name = __SWAIT_QUEUE_HEAD_INIT_ONSTACK(name)
78 # define DECLARE_SWAIT_QUEUE_HEAD_ONSTACK(name) \
79 DECLARE_SWAIT_QUEUE_HEAD(name)
82 static inline int swait_active(struct swait_queue_head *q)
84 return !list_empty(&q->task_list);
87 extern void swake_up(struct swait_queue_head *q);
88 extern void swake_up_all(struct swait_queue_head *q);
89 extern void swake_up_locked(struct swait_queue_head *q);
91 extern void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait);
92 extern void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state);
93 extern long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait, int state);
95 extern void __finish_swait(struct swait_queue_head *q, struct swait_queue *wait);
96 extern void finish_swait(struct swait_queue_head *q, struct swait_queue *wait);
98 /* as per ___wait_event() but for swait, therefore "exclusive == 0" */
99 #define ___swait_event(wq, condition, state, ret, cmd) \
101 struct swait_queue __wait; \
104 INIT_LIST_HEAD(&__wait.task_list); \
106 long __int = prepare_to_swait_event(&wq, &__wait, state);\
111 if (___wait_is_interruptible(state) && __int) { \
118 finish_swait(&wq, &__wait); \
122 #define __swait_event(wq, condition) \
123 (void)___swait_event(wq, condition, TASK_UNINTERRUPTIBLE, 0, \
126 #define swait_event(wq, condition) \
130 __swait_event(wq, condition); \
133 #define __swait_event_timeout(wq, condition, timeout) \
134 ___swait_event(wq, ___wait_cond_timeout(condition), \
135 TASK_UNINTERRUPTIBLE, timeout, \
136 __ret = schedule_timeout(__ret))
138 #define swait_event_timeout(wq, condition, timeout) \
140 long __ret = timeout; \
141 if (!___wait_cond_timeout(condition)) \
142 __ret = __swait_event_timeout(wq, condition, timeout); \
146 #define __swait_event_interruptible(wq, condition) \
147 ___swait_event(wq, condition, TASK_INTERRUPTIBLE, 0, \
150 #define swait_event_interruptible(wq, condition) \
154 __ret = __swait_event_interruptible(wq, condition); \
158 #define __swait_event_interruptible_timeout(wq, condition, timeout) \
159 ___swait_event(wq, ___wait_cond_timeout(condition), \
160 TASK_INTERRUPTIBLE, timeout, \
161 __ret = schedule_timeout(__ret))
163 #define swait_event_interruptible_timeout(wq, condition, timeout) \
165 long __ret = timeout; \
166 if (!___wait_cond_timeout(condition)) \
167 __ret = __swait_event_interruptible_timeout(wq, \
168 condition, timeout); \
172 #endif /* _LINUX_SWAIT_H */