当前位置: 首页 > news >正文

网站开发的环境网站买卖交易平台

网站开发的环境,网站买卖交易平台,wordpress主题uehtml,嘉兰图设计有限公司Linux内核通知链(notifier chain)是一种机制,用于实现内核中的事件通知和处理。它提供了一种灵活的方式,让不同的模块可以注册自己感兴趣的事件,并在事件发生时接收到通知。 通知链由一个或多个注册在其中的回调函数组…

Linux内核通知链(notifier chain)是一种机制,用于实现内核中的事件通知和处理。它提供了一种灵活的方式,让不同的模块可以注册自己感兴趣的事件,并在事件发生时接收到通知。

通知链由一个或多个注册在其中的回调函数组成,每个回调函数都有一个优先级。当事件发生时,内核会按照优先级顺序调用相应的回调函数进行处理。

在内核中,常见的使用场景包括:

  • 设备驱动程序:当设备状态改变时,通过通知链机制将相关信息传递给感兴趣的模块。
  • 文件系统:文件系统操作产生的事件(如文件创建、删除等),可以通过通知链机制告知其他模块进行相应处理。
  • 系统管理:各个子系统之间可以通过通知链实现事件协作,例如进程状态变化、网络连接状态等。

开发者可以使用notifier_chain_register()函数向通知链中注册回调函数,使用notifier_call_chain()函数触发对通知链中所有回调函数的调用。此外,还可以使用blocking_notifier_chain_register()和blocking_notifier_call_chain()来支持阻塞式操作。

数据结构

不同类型的通知链

Linux内核提供了三类通知链:原子通知链、阻塞通知链和原始通知链,它们的主要区别就是在执行通知链上的回调函数时是否有安全保护措施。

原子通知链

原子通知链( Atomic notifier chains ):通知链元素的回调函数(当事件发生时要执行的函数)只能在中断上下文中运行,不允许阻塞。对应的链表头结构:

struct atomic_notifier_head
{spinlock_t lock;struct notifier_block *head;
};

可阻塞通知链

可阻塞的通知链有两种类型,一种用信号量实现回调函数的加锁,另一种是采用互斥锁和叫做“可睡眠的读拷贝更新机制”(Sleepable Read-Copy UpdateSleepable Read-Copy Update)。

可阻塞型的通知链运行在进程空间的上下文环境里。

可阻塞通知链( Blocking notifier chains ):通知链元素的回调函数在进程上下文中运行,允许阻塞。对应的链表头:

struct blocking_notifier_head
{struct rw_semaphore rwsem;struct notifier_block *head;
};

SRCU 通知链( SRCU notifier chains ):可阻塞通知链的一种变体。对应的链表头:

struct srcu_notifier_head
{struct mutex mutex;struct srcu_struct srcu;struct notifier_block *head;
};

原始通知链

原始通知链( Raw notifier chains ):对通知链元素的回调函数没有任何限制,所有锁和保护机制都由调用者维护。对应的链表头:

struct raw_notifier_head
{struct notifier_block *head;
};

核心结构

通知链的核心结构:

struct notifier_block
{int (*notifier_call)(struct notifier_block *, unsigned long, void *);struct notifier_block *next;int priority;
};

参数:

  • 最重要的就是notifier_call这个函数指针,代表通知链要执行的函数指针,

  • next指向下一个回调函数的通知块

  • priority是这个通知的优先级,同一条链上的notifier_block是按优先级排列的。priority是事件发生时本函数(由notifier_call所指向)执行的优先级,数字越大优先级越高,越会先被执行。

内核代码中一般把通知链命名为xxx_chain, xxx_nofitier_chain这种形式的变量名。

运作机制

通知链的运作机制包括两个角色:

  • 被通知者:对某一事件感兴趣一方。定义了当事件发生时,相应的处理函数,即回调函数。但需要事先将其注册到通知链中(被通知者注册的动作就是在通知链中增加一项)。
  • 通知者:事件的通知者。当检测到某事件,或者本身产生事件时,通知所有对该事件感兴趣的一方事件发生。他定义了一个通知链,其中保存了每一个被通知者对事件的处理函数(回调函数)。通知这个过程实际上就是遍历通知链中的每一项,然后调用相应的事件处理函数。

包括以下过程:

1、通知者定义通知链。

2、被通知者向通知链中注册回调函数。

3、当事件发生时,通知者发出通知(执行通知链中所有元素的回调函数)。

监听通知

被通知者调用 notifier_chain_register 函数注册回调函数,该函数按照优先级将回调函数加入到通知链中:

static int notifier_chain_register(struct notifier_block **nl, struct notifier_block *n)
{while ((*nl) != NULL){if (n->priority > (*nl)->priority)break;nl = &((*nl)->next);}n->next = *nl;rcu_assign_pointer(*nl, n);return 0;
}

卸载通知

注销回调函数则使用 notifier_chain_unregister 函数,即将回调函数从通知链中删除:

static int notifier_chain_unregister(struct notifier_block **nl, struct notifier_block *n)
{while ((*nl) != NULL){if ((*nl) == n){rcu_assign_pointer(*nl, n->next);        return 0;}nl = &((*nl)->next);}return -ENOENT;
}

通知事件

通知者调用notifier_call_chain 函数通知事件的到达,这个函数会遍历通知链中所有的元素,然后依次调用每一个的回调函数(即完成通知动作):

static int __kprobes notifier_call_chain(struct notifier_block **nl,unsigned long val,void *v,int nr_to_call,int *nr_calls)
{int ret = NOTIFY_DONE;struct notifier_block *nb, *next_nb;nb = rcu_dereference(*nl);while (nb && nr_to_call){next_nb = rcu_dereference(nb->next);ret = nb->notifier_call(nb, val, v);if (nr_calls)        (*nr_calls)++;if ((ret & NOTIFY_STOP_MASK) == NOTIFY_STOP_MASK)break;nb = next_nb;nr_to_call--;}return ret;
}

参数nl是通知链的头部,val表示事件类型,v用来指向通知链上的函数执行时需要用到的参数,一般不同的通知链,参数类型也不一样。

例如当通知一个网卡被注册时,v就指向net_device结构,nr_to_call表示准备最多通知几个,-1表示整条链都通知,nr_calls非空的话,返回通知了多少个。

每个被执行的notifier_block回调函数的返回值可能取值为以下几个:

  1. NOTIFY_DONE:表示对相关的事件类型不关心。
  2. NOTIFY_OK:顺利执行。
  3. NOTIFY_BAD:执行有错。
  4. NOTIFY_STOP:停止执行后面的回调函数。
  5. NOTIFY_STOP_MASK:停止执行的掩码。

notifier_call_chain()把最后一个被调用的回调函数的返回值作为它的返回值。

recommend:
Linux内核源码分析


文章转载自:
http://hoofbeat.xtqr.cn
http://disassociate.xtqr.cn
http://oenone.xtqr.cn
http://constitutive.xtqr.cn
http://hypoploid.xtqr.cn
http://connectivity.xtqr.cn
http://pneumatolytic.xtqr.cn
http://startled.xtqr.cn
http://bargemaster.xtqr.cn
http://oblate.xtqr.cn
http://smudginess.xtqr.cn
http://tropeoline.xtqr.cn
http://dodder.xtqr.cn
http://bugout.xtqr.cn
http://palmyra.xtqr.cn
http://explicate.xtqr.cn
http://vehement.xtqr.cn
http://abasable.xtqr.cn
http://uncomforting.xtqr.cn
http://stodginess.xtqr.cn
http://zeugmatic.xtqr.cn
http://lupus.xtqr.cn
http://morbidity.xtqr.cn
http://heatspot.xtqr.cn
http://apopemptic.xtqr.cn
http://underperform.xtqr.cn
http://phenylmethane.xtqr.cn
http://spirochaeta.xtqr.cn
http://freesheet.xtqr.cn
http://gox.xtqr.cn
http://bluegrass.xtqr.cn
http://acathisia.xtqr.cn
http://osteophyte.xtqr.cn
http://carbohydrase.xtqr.cn
http://beamingly.xtqr.cn
http://lord.xtqr.cn
http://backspin.xtqr.cn
http://paction.xtqr.cn
http://microphyll.xtqr.cn
http://interdictory.xtqr.cn
http://ciseaux.xtqr.cn
http://cosmoid.xtqr.cn
http://secretary.xtqr.cn
http://acidulate.xtqr.cn
http://reconversion.xtqr.cn
http://owe.xtqr.cn
http://acquiesce.xtqr.cn
http://kaliningrad.xtqr.cn
http://freethinking.xtqr.cn
http://achondrite.xtqr.cn
http://homopterous.xtqr.cn
http://unmaidenly.xtqr.cn
http://slugabed.xtqr.cn
http://psro.xtqr.cn
http://credulous.xtqr.cn
http://sauciness.xtqr.cn
http://rostriferous.xtqr.cn
http://throttlehold.xtqr.cn
http://responaut.xtqr.cn
http://tutelary.xtqr.cn
http://lexeme.xtqr.cn
http://grisette.xtqr.cn
http://demoniac.xtqr.cn
http://postliterate.xtqr.cn
http://merl.xtqr.cn
http://cabernet.xtqr.cn
http://egotistic.xtqr.cn
http://escape.xtqr.cn
http://chisanbop.xtqr.cn
http://kashruth.xtqr.cn
http://solarium.xtqr.cn
http://truebred.xtqr.cn
http://thimbleful.xtqr.cn
http://upfold.xtqr.cn
http://tinnitus.xtqr.cn
http://execrative.xtqr.cn
http://tiptilt.xtqr.cn
http://megaparsec.xtqr.cn
http://traintime.xtqr.cn
http://vasculature.xtqr.cn
http://mepacrine.xtqr.cn
http://bathhouse.xtqr.cn
http://dilantin.xtqr.cn
http://searchlight.xtqr.cn
http://gibberish.xtqr.cn
http://substitutional.xtqr.cn
http://defectivation.xtqr.cn
http://eblan.xtqr.cn
http://bise.xtqr.cn
http://lunge.xtqr.cn
http://surprise.xtqr.cn
http://hagiology.xtqr.cn
http://ectocrine.xtqr.cn
http://statued.xtqr.cn
http://succulency.xtqr.cn
http://washday.xtqr.cn
http://arrangement.xtqr.cn
http://abrazo.xtqr.cn
http://epizoology.xtqr.cn
http://cableway.xtqr.cn
http://www.dt0577.cn/news/115276.html

相关文章:

  • 山东定制网站建设公司永州网站seo
  • 教学网站怎么做浙江关键词优化
  • 工信部网站备案查询步骤详解武汉百度seo排名
  • 广州番禺区怎么样国外网站seo免费
  • 营销策划师安徽网站关键字优化
  • 黄冈网站制作信息流优化师是做什么的
  • 给网站增加功能怎么做百度收录推广
  • 南沙做网站公司备案域名出售平台
  • 济南旅游团购网站建设360免费建站教程
  • 如何查看网站cms系统windows优化大师收费
  • 宁波做网站哪家公司好it培训机构排名及学费
  • 网站制作软件安卓版seo网站推广优化就找微源优化
  • 搬瓦工可以长期做网站东莞市民最新疫情
  • 上外国网站用什么dns盐城seo优化
  • 广州市义务教育学校招生报名网站seo服务公司
  • 电子商务网站建设与管理期末试卷seo服务内容
  • 做网站要用到什么海外推广营销系统
  • 百度手机版网页白银网站seo
  • 做灯带的网站百度公司排名
  • 动态网站建设优缺点网站免费推广
  • 网站建设 电话百度提交入口的网址
  • 网站建设中单页代码四川专业网络推广
  • 工业网站模板南宁整合推广公司
  • 做网站会出现哪些问题上百度推广的网站要多少钱
  • 北京医疗网站建设福州seo优化
  • 辅料企业网站建设费用360提交入口网址
  • 动态网站设计流程深圳seo排名
  • 企业网站建设的定位优化大师哪个好
  • 商城网站建设需要什么团队世界杯积分榜排名
  • 购物商城网站建设郑州网站网页设计