一.头文件
#include <linux/notifier.h>
二.结构体
//通知块
struct notifier_block {
int (*notifier_call)(struct notifier_block *, unsigned long, void *); //回调函数
struct notifier_block __rcu *next; //指向通知链表的下一项
int priority; //优先级
};
//原子通知链 运行在中断上下文,不允许阻塞
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;
};
//SRCU通知链 阻塞通知链的变体
struct srcu_notifier_head {
struct mutex mutex;
struct srcu_struct srcu;
struct notifier_block __rcu *head;
};
三.通知链头初始化
调用定义好的宏初始化通知链表头
#define ATOMIC_NOTIFIER_HEAD(name) \
struct atomic_notifier_head name = ATOMIC_NOTIFIER_INIT(name)
#defi