当前位置:网站首页>DECLARE_ WAIT_ QUEUE_ HEAD、wake_ up_ Interruptible macro analysis

DECLARE_ WAIT_ QUEUE_ HEAD、wake_ up_ Interruptible macro analysis

2022-07-05 03:13:00 _ Zer0

DECLARE_WAIT_QUEUE_HEAD

// Source code 
struct list_head {
    
	struct list_head *next, *prev;
};

struct __wait_queue_head {
    
    spinlock_t lock;
    struct list_head task_list;
};

typedef struct __wait_queue_head wait_queue_head_t;

#define DECLARE_WAIT_QUEUE_HEAD (name) 
        wait_queue_head_t name = __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 } 
}

//DECLARE_WAIT_QUEUE_HEAD(wq); The result of unlocking the macro definition statement is as follows 
wait_queue_head_t wq = {
                        
    .lock       = __SPIN_LOCK_UNLOCKED(wq.lock),               
    .task_list = {
     &(wq).task_list, &(wq).task_list } 
}

#include <linux/wait.h>
// The following two lines are equivalent to DECLARE_WAIT_QUEUE_HEAD(wq);
wait_queue_head_t wq;
init_waitqueue_head(&wq);   

wake_up_interruptible

#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);
}
原网站

版权声明
本文为[_ Zer0]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140805052000.html