您的位置:首页 > 运维架构 > Linux

linux notification内核通知链

2016-03-25 17:34 513 查看
/******linux notification内核通知链***********/

linux/notifier.h //内核中的一处来告知内核另一处某事件的发生,并执行注册的

struct notifier_block { //notifier_call方法。

int (*notifier_call)(struct notifier_block *self,unsigned long,void*);

struct notifier_block *next;

int priority;

};//notifier_call必须注册,大priority优先执行。

struct blocking_notifier_head {

struct rw_semaphore rwsem;

struct notifier_block *head;

}

struct atomic_notifier_head {

spinlock_t lock;

struct notifier_block *head;

}

BLOCKING_NOTIFIER_HEAD(name); (1)
//两种方法阻塞型初始化通知链头

struct blocking_notifier_head name; //用于可以阻塞的环境

BLOCKING_INIT_NOTIFIER_HEAD(name); (2)

int blocking_notifier_chain_register(struct blocking_notifier_head *chain,

struct notifier_block *nf);//注册一个通知到通知链上去

int blocking_notifier_chain_unregister(struct blocking_notifier_head *chain,

struct notifier_block *fn);

int blocking_notifier_call_chain(struct blocking_notifier_head *chain,

unsigned long event,void* data);//轮循每个通知,并执行其中的函数

ATOMIC_NOTIFIER_HEAD(name); (1) //原子型,同上

struct atomic_notifier_head name; //用于原子型环境,比如中断

ATOMIC_INIT_NOTIFIER_HEAD(name); (2)

int atomic_notifier_chain_register(struct atomic_notifier_head *chain,

struct notifier_block *nf);

int atomic_notifier_chain_unregister(struct atomic_notifier_head *chain,

struct notifier_block *nf);

int atomic_notifier_call_chain(struct blocking_notifier_head *chain,

unsigned long event,void* data)

/* notifier_call有几个常用可选的返回值:NOTIFY_OK,NOTIFY_STOP,NOTIFY_BAD代

* 表不同的结束意义。

*/
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: