linux-old/include/linux/wait.h
<<
>>
Prefs
   1#ifndef _LINUX_WAIT_H
   2#define _LINUX_WAIT_H
   3
   4#define WNOHANG         0x00000001
   5#define WUNTRACED       0x00000002
   6
   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 */
  10
  11#ifdef __KERNEL__
  12
  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>
  18
  19#include <asm/page.h>
  20#include <asm/processor.h>
  21
  22/*
  23 * Debug control.  Slow but useful.
  24 */
  25#if defined(CONFIG_DEBUG_WAITQ)
  26#define WAITQUEUE_DEBUG 1
  27#else
  28#define WAITQUEUE_DEBUG 0
  29#endif
  30
  31struct __wait_queue {
  32        unsigned int flags;
  33#define WQ_FLAG_EXCLUSIVE       0x01
  34        struct task_struct * task;
  35        struct list_head task_list;
  36#if WAITQUEUE_DEBUG
  37        long __magic;
  38        long __waker;
  39#endif
  40};
  41typedef struct __wait_queue wait_queue_t;
  42
  43/*
  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.
  48 */
  49#define USE_RW_WAIT_QUEUE_SPINLOCK 0
  50
  51#if USE_RW_WAIT_QUEUE_SPINLOCK
  52# define wq_lock_t rwlock_t
  53# define WAITQUEUE_RW_LOCK_UNLOCKED RW_LOCK_UNLOCKED
  54
  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
  63#else
  64# define wq_lock_t spinlock_t
  65# define WAITQUEUE_RW_LOCK_UNLOCKED SPIN_LOCK_UNLOCKED
  66
  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
  75#endif
  76
  77struct __wait_queue_head {
  78        wq_lock_t lock;
  79        struct list_head task_list;
  80#if WAITQUEUE_DEBUG
  81        long __magic;
  82        long __creator;
  83#endif
  84};
  85typedef struct __wait_queue_head wait_queue_head_t;
  86
  87
  88/*
  89 * Debugging macros.  We eschew `do { } while (0)' because gcc can generate
  90 * spurious .aligns.
  91 */
  92#if WAITQUEUE_DEBUG
  93#define WQ_BUG()        BUG()
  94#define CHECK_MAGIC(x)                                                  \
  95        do {                                                                    \
  96                if ((x) != (long)&(x)) {                                        \
  97                        printk("bad magic %lx (should be %lx), ",               \
  98                                (long)x, (long)&(x));                           \
  99                        WQ_BUG();                                               \
 100                }                                                               \
 101        } while (0)
 102#define CHECK_MAGIC_WQHEAD(x)                                                   \
 103        do {                                                                    \
 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);   \
 107                        WQ_BUG();                                               \
 108                }                                                               \
 109        } while (0)
 110#define WQ_CHECK_LIST_HEAD(list)                                                \
 111        do {                                                                    \
 112                if (!(list)->next || !(list)->prev)                             \
 113                        WQ_BUG();                                               \
 114        } while(0)
 115#define WQ_NOTE_WAKER(tsk)                                                      \
 116        do {                                                                    \
 117                (tsk)->__waker = (long)__builtin_return_address(0);             \
 118        } while (0)
 119#else
 120#define WQ_BUG()
 121#define CHECK_MAGIC(x)
 122#define CHECK_MAGIC_WQHEAD(x)
 123#define WQ_CHECK_LIST_HEAD(list)
 124#define WQ_NOTE_WAKER(tsk)
 125#endif
 126
 127/*
 128 * Macros for declaration and initialization of the datatypes
 129 */
 130
 131#if WAITQUEUE_DEBUG
 132# define __WAITQUEUE_DEBUG_INIT(name) (long)&(name).__magic, 0
 133# define __WAITQUEUE_HEAD_DEBUG_INIT(name) (long)&(name).__magic, (long)&(name).__magic
 134#else
 135# define __WAITQUEUE_DEBUG_INIT(name)
 136# define __WAITQUEUE_HEAD_DEBUG_INIT(name)
 137#endif
 138
 139#define __WAITQUEUE_INITIALIZER(name, tsk) {                            \
 140        task:           tsk,                                            \
 141        task_list:      { NULL, NULL },                                 \
 142                         __WAITQUEUE_DEBUG_INIT(name)}
 143
 144#define DECLARE_WAITQUEUE(name, tsk)                                    \
 145        wait_queue_t name = __WAITQUEUE_INITIALIZER(name, tsk)
 146
 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)}
 151
 152#define DECLARE_WAIT_QUEUE_HEAD(name) \
 153        wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name)
 154
 155static inline void init_waitqueue_head(wait_queue_head_t *q)
 156{
 157#if WAITQUEUE_DEBUG
 158        if (!q)
 159                WQ_BUG();
 160#endif
 161        q->lock = WAITQUEUE_RW_LOCK_UNLOCKED;
 162        INIT_LIST_HEAD(&q->task_list);
 163#if WAITQUEUE_DEBUG
 164        q->__magic = (long)&q->__magic;
 165        q->__creator = (long)current_text_addr();
 166#endif
 167}
 168
 169static inline void init_waitqueue_entry(wait_queue_t *q, struct task_struct *p)
 170{
 171#if WAITQUEUE_DEBUG
 172        if (!q || !p)
 173                WQ_BUG();
 174#endif
 175        q->flags = 0;
 176        q->task = p;
 177#if WAITQUEUE_DEBUG
 178        q->__magic = (long)&q->__magic;
 179#endif
 180}
 181
 182static inline int waitqueue_active(wait_queue_head_t *q)
 183{
 184#if WAITQUEUE_DEBUG
 185        if (!q)
 186                WQ_BUG();
 187        CHECK_MAGIC_WQHEAD(q);
 188#endif
 189
 190        return !list_empty(&q->task_list);
 191}
 192
 193static inline void __add_wait_queue(wait_queue_head_t *head, wait_queue_t *new)
 194{
 195#if WAITQUEUE_DEBUG
 196        if (!head || !new)
 197                WQ_BUG();
 198        CHECK_MAGIC_WQHEAD(head);
 199        CHECK_MAGIC(new->__magic);
 200        if (!head->task_list.next || !head->task_list.prev)
 201                WQ_BUG();
 202#endif
 203        list_add(&new->task_list, &head->task_list);
 204}
 205
 206/*
 207 * Used for wake-one threads:
 208 */
 209static inline void __add_wait_queue_tail(wait_queue_head_t *head,
 210                                                wait_queue_t *new)
 211{
 212#if WAITQUEUE_DEBUG
 213        if (!head || !new)
 214                WQ_BUG();
 215        CHECK_MAGIC_WQHEAD(head);
 216        CHECK_MAGIC(new->__magic);
 217        if (!head->task_list.next || !head->task_list.prev)
 218                WQ_BUG();
 219#endif
 220        list_add_tail(&new->task_list, &head->task_list);
 221}
 222
 223static inline void __remove_wait_queue(wait_queue_head_t *head,
 224                                                        wait_queue_t *old)
 225{
 226#if WAITQUEUE_DEBUG
 227        if (!old)
 228                WQ_BUG();
 229        CHECK_MAGIC(old->__magic);
 230#endif
 231        list_del(&old->task_list);
 232}
 233
 234#endif /* __KERNEL__ */
 235
 236#endif
 237
lxr.linux.no kindly hosted by Redpill Linpro AS, provider of Linux consulting and operations services since 1995.