鱼C论坛

 找回密码
 立即注册
查看: 2667|回复: 1

[技术交流] linux notification内核通知链

[复制链接]
发表于 2016-3-29 11:02:43 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
/******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代
*   表不同的结束意义。
*/
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2016-6-14 10:34:10 | 显示全部楼层
感谢分享
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-3-29 06:41

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表