init_waitqueue_func_entry
使用自定义的函数作为等待队列中的进程唤醒事件
static inline void
init_waitqueue_func_entry(struct wait_queue_entry *wq_entry, wait_queue_func_t func)
{
  wq_entry->flags   = 0;
  wq_entry->private = NULL;
  wq_entry->func    = func;
}例子
// 回调事件ep_poll_callback
init_waitqueue_func_entry(&pwq->wait, ep_poll_callback);waitqueue_active
returns true if the wait list is not empty
如果等待列表不为空,则返回 true
static inline int waitqueue_active(struct wait_queue_head *wq_head)
{
  return !list_empty(&wq_head->head);
}add_wait_queue
wait.c
// add_wait_queue()实现将等待队列元素插入等待队列第一个元素的位置
void add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
{
  unsigned long flags;
  wq_entry->flags &= ~WQ_FLAG_EXCLUSIVE; //并设置等待队列元素的flags值为非WQ_FLAG_EXCLUSIVE,即为0,表示此进程不是高优先级进程
  spin_lock_irqsave(&wq_head->lock, flags); //保存本地中断状态 关闭中断 获取自旋锁
  __add_wait_queue(wq_head, wq_entry); // 将等待项,加入到等待队列头部
  spin_unlock_irqrestore(&wq_head->lock, flags);   //恢复本地中断状态 释放锁
}__add_wait_queue
wait.h
static inline void __add_wait_queue(struct wait_queue_head *wq_head, struct wait_queue_entry *wq_entry)
{
  struct list_head *head = &wq_head->head;
  struct wait_queue_entry *wq;
  list_for_each_entry(wq, &wq_head->head, entry) {
    if (!(wq->flags & WQ_FLAG_PRIORITY))
      break;
    head = &wq->entry;
  }
  list_add(&wq_entry->entry, head); 
}struct list_head
kernel/inclue/linux/types.h
struct list_head {
  struct list_head *next, *prev;
};wait_queue_head
wait.h
struct wait_queue_head {
  spinlock_t    lock;  //自旋锁
  struct list_head  head;
};wait_queue_head_t
wait.h
typedef struct wait_queue_head wait_queue_head_t;
typedef  struct wait_queue_head 别名









