首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

try_module_get跟module_put

2013-02-17 
try_module_get和module_puttry_module_get注解:1位置:/linux/kernel/module.c2声明:static inline intt

try_module_get和module_put
try_module_get注解:        1>位置:/linux/kernel/module.c

        2>声明:static inline int  try_module_get(structmodule *module)

        3>功能:判断module模块是否处于活动状态,然后通过local_inc()宏将该模块的引用计数加1

        4>返回值:

linux-2.6中返回值是一个整数,如果该模块处于活动状态且对它引用计数加1操作正确则返回1,否则返回0

linux-3.7.5中返回值是一个bool量,正确返回true,错误返回false!

实现方式Linux-2.6

[root@root hello模块]# Message from syslogd@localhost at Feb  2 09:07:45 ... kernel:module_refcount(module):1Message from syslogd@localhost at Feb  2 09:07:45 ... kernel:module_refcount(module):2 Message from syslogd@localhost at Feb  2 09:07:45 ... kernel:module_refcount(module):1

由上面的程序可以看出来在模块加载的过程中,模块的使用量就是1了,然后用try_module_get把使用量变为2,再使用module_put把使用量变为1,加载完成后使用量为0开始写程序的时候把module_put写在了__eixt中,导致加载了模块使用量一直为1,无法卸载只能重启!后来才知道rmmod是在调用module_exit之前检查模块的引用计数的,所以在exit之前就应该要module_put释放引用计数,这样一来把module_put写在init里面就可以解决了!

热点排行