#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/notifier.h>
struct srcu_notifier_head srcu_event;
static int notifier_call_test_event(struct notifier_block *nb,
unsigned long event, void *data)
{
printk(KERN_ALERT "notifier_call_test_event start\n");
printk(KERN_ALERT "%s\n", (char *)data);
return 0;
}
struct notifier_block nb = {
.notifier_call = notifier_call_test_event,
};
static int srcu_notifier_head_init(void)
{
srcu_init_notifier_head(&srcu_event);
srcu_notifier_chain_register(&srcu_event, &nb);
printk(KERN_ALERT "srcu_notifier_head_init start\n");
return 0;
}
static void srcu_notifier_head_exit(void)
{
printk(KERN_ALERT "GoodBye srcu_notifier_head Test\n");
}
module_init(srcu_notifier_head_init);
module_exit(srcu_notifier_head_exit);
#include <linux/module.h>
#include <linux/init.h>
#include <linux/device.h>
#include <linux/notifier.h>
extern struct srcu_notifier_head srcu_event;
static int srcu_notifier_device_init(void)
{
srcu_notifier_call_chain(&srcu_event, 1, (void *)"hanhao");
printk(KERN_ALERT "srcu_notifier_device_init start\n");
return 0;
}
static void srcu_notifier_device_exit(void)
{
printk(KERN_ALERT "GoodBye wake up source Test\n");
}
late_initcall(srcu_notifier_device_init);
module_exit(srcu_notifier_device_exit);
运行结果如下:
\par \cf0\highlight0 [ 4.439727][ T1] srcu_notifier_head_init start\cf1\highlight2
\par \cf0\highlight0 [ 5.020833][ T1] notifier_call_test_event start\cf1\highlight2
\par \cf0\highlight0 [ 5.020841][ T1] hanhao\cf1\highlight2
\par \cf0\highlight0 [ 5.020846][ T1] srcu_notifier_device_init start\cf1\highlight2