现在的位置: 首页 > 综合 > 正文

list_head wait_queue_head_t

2013年03月19日 ⁄ 综合 ⁄ 共 1293字 ⁄ 字号 评论关闭

#define LIST_HEAD_INIT(&name){ &(name),&(name)}

#define LIST_HEAD(name) struct list_head name = LIST_HEAD_INIT(name);

初始化:

struct list_head queue_head;

LIST_HEAD_INIT(&queue_head);

判断是否为空:

static inline int list_empty(const struct list_head *head);

插入:

static inline void list_add(struct list_head *new,struct list_head *head);//在head后插入

 

static inline void list_add_tail(struct list_head *new,struct list_head *head);//在head之前插入

 

删除:

static inline void list_del(struct list_head *entry);

 

遍历:

a)由链表节点到数据项变量

list_entry(ptr,type,member);

ptr指向该数据中list_head成员,type是数据项的类型,member则是数据项类型中成员的变量名。

 

 

wait_queue_head_t:

头文件:#include <linux/wait.h>

定义:wait_queue_head_t my_queue;

初始化:init_waitqueue_head(&my_queue);

在一个函数里面等待:wait_event(queue,condition);

在另一个函数里面唤醒:wake_up(wait_queue_head_t *queue);

 

 

linux中最简单的休眠方式是下面的宏,
wait_event(queue, condition)/* 进程将被置于非中断休眠(uninterruptible sleep)*/
wait_event_interruptible(queue, condition)/*进程可被信号中断休眠,返回非0值表示休眠被信号中断*/
wait_event_timeout(queue, condition, timeout) /*等待限定时间jiffy,condition满足其一返回0*/
wait_event_interruptible_timeout(queue, condition, timeout)
queue是等待队列头,传值方式
condition是任意一个布尔表达式,在休眠前后多次对condition求值,为真则唤醒

唤醒进程的基本函数是wake_up
void wake_up(wait_queue_head_t *queue);/*唤醒等待在给定queue上的所有进程*/
void wake_up_interruptible(wait_queue_head_t *queue);

实践中,一般是wait_event和
wake_up,
wait_event_interruptible和wake_up_interruptible 成对使用。

 

 

 

 

 

 

 

抱歉!评论已关闭.