4 #define WNOHANG 0x00000001
5 #define WUNTRACED 0x00000002
7 #define __WNOTHREAD 0x20000000 /* Don't wait on children of other threads in this group */
8 #define __WALL 0x40000000 /* Wait on all children, regardless of type */
9 #define __WCLONE 0x80000000 /* Wait only on non-SIGCHLD children */
13 #include <linux/kernel.h>
14 #include <linux/list.h>
15 #include <linux/stddef.h>
16 #include <linux/spinlock.h>
17 #include <linux/config.h>
20 #include <asm/processor.h>
23 * Debug control. Slow but useful.
25 #if defined(CONFIG_DEBUG_WAITQ)
26 #define WAITQUEUE_DEBUG 1
28 #define WAITQUEUE_DEBUG 0
33 #define WQ_FLAG_EXCLUSIVE 0x01
34 struct task_struct * task;
35 struct list_head task_list;
41 typedef struct __wait_queue wait_queue_t;
44 * 'dual' spinlock architecture. Can be switched between spinlock_t and
45 * rwlock_t locks via changing this define. Since waitqueues are quite
46 * decoupled in the new architecture, lightweight 'simple' spinlocks give
47 * us slightly better latencies and smaller waitqueue structure size.
49 #define USE_RW_WAIT_QUEUE_SPINLOCK 0
51 #if USE_RW_WAIT_QUEUE_SPINLOCK
52 # define wq_lock_t rwlock_t
53 # define WAITQUEUE_RW_LOCK_UNLOCKED RW_LOCK_UNLOCKED
55 # define wq_read_lock read_lock
56 # define wq_read_lock_irqsave read_lock_irqsave
57 # define wq_read_unlock_irqrestore read_unlock_irqrestore
58 # define wq_read_unlock read_unlock
59 # define wq_write_lock_irq write_lock_irq
60 # define wq_write_lock_irqsave write_lock_irqsave
61 # define wq_write_unlock_irqrestore write_unlock_irqrestore
62 # define wq_write_unlock write_unlock
64 # define wq_lock_t spinlock_t
65 # define WAITQUEUE_RW_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED
67 # define wq_read_lock spin_lock
68 # define wq_read_lock_irqsave spin_lock_irqsave
69 # define wq_read_unlock spin_unlock
70 # define wq_read_unlock_irqrestore spin_unlock_irqrestore
71 # define wq_write_lock_irq spin_lock_irq
72 # define wq_write_lock_irqsave spin_lock_irqsave
73 # define wq_write_unlock_irqrestore spin_unlock_irqrestore
74 # define wq_write_unlock spin_unlock
77 struct __wait_queue_head {
79 struct list_head task_list;
85 typedef struct __wait_queue_head wait_queue_head_t;
89 * Debugging macros. We eschew `do { } while (0)' because gcc can generate
93 #define WQ_BUG() BUG()
94 #define CHECK_MAGIC(x) \
96 if ((x) != (long)&(x)) { \
97 printk("bad magic %lx (should be %lx), ", \
98 (long)x, (long)&(x)); \
102 #define CHECK_MAGIC_WQHEAD(x) \
104 if ((x)->__magic != (long)&((x)->__magic)) { \
105 printk("bad magic %lx (should be %lx, creator %lx), ", \
106 (x)->__magic, (long)&((x)->__magic), (x)->__creator); \
110 #define WQ_CHECK_LIST_HEAD(list) \
112 if (!(list)->next || !(list)->prev) \
115 #define WQ_NOTE_WAKER(tsk) \
117 (tsk)->__waker = (long)__builtin_return_address(0); \
121 #define CHECK_MAGIC(x)
122 #define CHECK_MAGIC_WQHEAD(x)
123 #define WQ_CHECK_LIST_HEAD(list)
124 #define WQ_NOTE_WAKER(tsk)
128 * Macros for declaration and initialisaton of the datatypes
132 # define __WAITQUEUE_DEBUG_INIT(name) (long)&(name).__magic, 0
133 # define __WAITQUEUE_HEAD_DEBUG_INIT(name) (long)&(name).__magic, (long)&(name).__magic
135 # define __WAITQUEUE_DEBUG_INIT(name)
136 # define __WAITQUEUE_HEAD_DEBUG_INIT(name)
139 #define __WAITQUEUE_INITIALIZER(name, tsk) { \
141 task_list: { NULL, NULL }, \
142 __WAITQUEUE_DEBUG_INIT(name)}
144 #define DECLARE_WAITQUEUE(name, tsk) \
145 wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
147 #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
148 lock: WAITQUEUE_RW_LOCK_UNLOCKED, \
149 task_list: { &(name).task_list, &(name).task_list }, \
150 __WAITQUEUE_HEAD_DEBUG_INIT(name)}
152 #define DECLARE_WAIT_QUEUE_HEAD(name) \
153 wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
155 static inline void init_waitqueue_head(wait_queue_head_t *q)
161 q->lock = WAITQUEUE_RW_LOCK_UNLOCKED;
162 INIT_LIST_HEAD(&q->task_list);
164 q->__magic = (long)&q->__magic;
165 q->__creator = (long)current_text_addr();
169 static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
178 q->__magic = (long)&q->__magic;
182 static inline int waitqueue_active(wait_queue_head_t *q)
187 CHECK_MAGIC_WQHEAD(q);
190 return !list_empty(&q->task_list);
193 static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
198 CHECK_MAGIC_WQHEAD(head);
199 CHECK_MAGIC(new->__magic);
200 if (!head->task_list.next || !head->task_list.prev)
203 list_add(&new->task_list, &head->task_list);
207 * Used for wake-one threads:
209 static inline void __add_wait_queue_tail(wait_queue_head_t *head,
215 CHECK_MAGIC_WQHEAD(head);
216 CHECK_MAGIC(new->__magic);
217 if (!head->task_list.next || !head->task_list.prev)
220 list_add_tail(&new->task_list, &head->task_list);
223 static inline void __remove_wait_queue(wait_queue_head_t *head,
229 CHECK_MAGIC(old->__magic);
231 list_del(&old->task_list);
234 #endif /* __KERNEL__ */