notification chains 简介

来源:互联网 发布:ubuntu卸载virtualbox 编辑:程序博客网 时间:2024/05/19 10:38

Why notification chains

    Notification chain 应用于Linux内核各子系统之间,有时一个子系统会关心另外一个子系统发生的事件,这时就可以注册一个关心那个时间的chain。典型例子是USB设备拔插,网络接口的使用。

使用限制

    1,仅用于内核的子系统之间。应用层请使用常规进程通信手段如信号量,信号,socket,共享内存,共享文件等。内核到上层的接口有proc,sysctl,sysfs等。

    2,在多CPU的机器中,有可能存在多个CPU同时调用notifier_call_chain函数来通知同一个notification chain。所以如果回调函数需要处理临界区域,回调函数需要自己维护互斥关系。

数据结构

struct notifier_block {
       int (*notifier_call)(struct notifier_block *, unsighed long ,void *);  //  回调函数
       struct notifier_block *next;  //指向下一个注册项
       int priority;    //  优先级
}


内核中的Sample Chains

       inetaddr_chain
       inet6addr_chain
       netdev_chain

function

    notifier_chain_register(struct notifier_block **nl,struct notifier_block *n)  //notification 注册

    notifier_chain_unregiser(struct notifier_block **nl , struct notifier_block *n) // notification 注销

   /* 通知函数,当某事件发生时调用该函数

  @nl: 指向需要通知chain的头

  @val: 回调函数使用的参数

  @v:回调函数使用的指针

  @nr_to_call :没明白呢 Numer of notifier function to be called 

  @nr_call  :Records the number of notifications sent

  @returns : 回调函数的返回值

*/

    notifier_call_chain(struct notifier_block **nl , unsighed long val , void *v ,int nr_to_call, int *nr_calls)   

    some wrapper function

原创粉丝点击