1,、static DECLARE_WAIT_QUEUE_HEAD(button_waitq); DECLARE_WAIT_QUEUE_HEAD是一個宏,,定義如下: #define DECLARE_WAIT_QUEUE_HEAD(name) \ wait_queue_head_t name = __WAIT_QUEUE_HEAD_INITIALIZER(name) wait_queue_head_t也是一個宏,,定義如下: typedef struct __wait_queue_head wait_queue_head_t; struct __wait_queue_head { spinlock_t lock; struct list_head task_list; }; __WAIT_QUEUE_HEAD_INITIALIZER(name)也是一個宏,定義如下: #define __WAIT_QUEUE_HEAD_INITIALIZER(name) { \ .lock = __SPIN_LOCK_UNLOCKED(name.lock), \ .task_list = { &(name).task_list, &(name).task_list } } 所以,,static DECLARE_WAIT_QUEUE_HEAD(button_waitq);相當(dāng)于定義了一個名為button_waitq struct __wait_queue_head類型的結(jié)構(gòu)體變量,,并初始化為: .lock = __SPIN_LOCK_UNLOCKED(name.lock), .task_list = { &(name).task_list, &(name).task_list } 意義:定義一個名為button_waitq的隊列頭,代表該進程,。 2,、wait_event_interruptible(button_waitq, ev_press); #define wait_event_interruptible(wq, condition) \ ({ \ int __ret = 0; \ if (!(condition)) \ __wait_event_interruptible(wq, condition, __ret); \ __ret; \ }) 當(dāng)條件condition為0是調(diào)用__wait_event_interruptible(wq, condition, __ret)進行休眠; 3,、wake_up_interruptible(&button_waitq); #define wake_up_interruptible(x) __wake_up(x, TASK_INTERRUPTIBLE, 1, NULL) void __wake_up(wait_queue_head_t *q, unsigned int mode, int nr_exclusive, void *key) { unsigned long flags; spin_lock_irqsave(&q->lock, flags); __wake_up_common(q, mode, nr_exclusive, 0, key); spin_unlock_irqrestore(&q->lock, flags); } 喚醒button_waitq隊列頭代表的進程,。
|
|