一、概述
linux内核通知链技术能够在子系统之间使用,通知其它子系统发生事件变化,但是不能在内核空间和用户空间进行事件的通知。
二、数据结构
1. 通知
struct notifier_block {
notifier_fn_t notifier_call; //回调函数
int priority; //优先级
};
typedef int (*notifier_fn_t)(struct notifier_block *nb, unsigned long action, void *data);
2. 通知链
/* 原子通知链在中断或者原子操作上下文中运行,不允许阻塞 */
struct atomic_notifier_head {
spinlock_t lock; //自旋锁
struct notifier_block __rcu *head; //通知链头
};
/* 可阻塞通知链在进程上下文中运行,可以阻塞 */
struct blocking_notifier_head {
struct rw_semaphore rwsem; //信号量
struct notifier_block __rcu *head; //通知链头
};
/* 原始通知链可在中断、原子、进程上下文使用,但是锁和保护机制需要使用者维护 */
struct raw_notifier_head {
struct notifier_block __rcu *head; //通知链头
};
三、创建通知链
/* 定义原子通知链 */
#define ATOMIC_NOTIFIER_HEAD(name)
/* 定义可阻塞通知链 */
#define