等待队列(wait_queue)表示一组睡眠的进程, 当某种条件为真的时候, 由内核来唤醒它们.
等待队列由双向链表来实现, 每一个等待队列都有一个等待队列头(wait_queue_head).
struct __wait_queue_head {
spinlock_t lock;
struct list_head task_list;
};
typedef struct __wait_queue_head wait_queue_head_t;
由于等待队列经常由中断处理和其他的内核函数来修改所以要对其数据进行保护所以此处使用了spin_lock.
wait_queue_t:
struct __wait_queue {
unsigned int flags;
#define WQ_FLAG_EXCLUSIVE 0x01
void *private;
wait_queue_func_t func;
struct list_head task_list;
};
通过DEFINE_WAIT或者DECLARE_WAIT_QUEUE_HEAD来定义一个等待队列
#define DEFINE_WAIT(name) \
wait_queue_t name = { \
.private = current, \
.func = autoremove_wake_function, \
.task_list = LIST_HEAD_INIT((name).task_list), \
}
/* DECLARE_WAIT_QUEUE */
#define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \
.lock