notification chains 简介

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值