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

建设部四库一平台网站婚庆公司策划书

建设部四库一平台网站,婚庆公司策划书,直播软件推荐,网站做优化有必要吗目录#xff08;一#xff09;内核定时器介绍#xff08;二#xff09;内核定时器相关接口#xff08;三#xff09;使用步骤#xff08;四#xff09;实例代码#xff08;一#xff09;内核定时器介绍 内核定时器并不是用来简单的定时操作#xff0c;而是在定时时… 目录一内核定时器介绍二内核定时器相关接口三使用步骤四实例代码一内核定时器介绍 内核定时器并不是用来简单的定时操作而是在定时时间后触发事件的操作类似定时器中断是内核用来控制在未来某个时间点基于jiffies调度执行某个函数的一种机制内核中采用的定时器以jiffies为单位。 单位秒jiffies/HZ 几个重要跟时间有关的名词或变数 HZLinux核心每隔固定周期会发出timer interrupt (IRQ 0)HZ是用来定义每一秒有几次timer interrupts。举例来说HZ为1000代表每秒有1000次timer interrupts。 TickTick是HZ的倒数意即timer interrupt每发生一次中断的时间。如HZ为250时tick为4毫秒(millisecond)。 JiffiesJiffies为Linux核心变数(unsigned long)它被用来记录系统自开机以来已经过了多少tick。每发生一次timer interruptJiffies变数会被加一。值得注意的是Jiffies于系统开机时并非初始化成零而是被设为-300*HZ 类似Linux系统中time日历时间二内核定时器相关接口 和定时器先关的数据结构 struct timer_list {unsigned long expires; //未来时间点即超时时间void (*function)(unsigned long);//超时回调函数unsigned long data; //传递给回调函数的数据也就是定时器数据 };初始化定时器相关的数据结构 1. 静态定以定时器数据结构 #define DEFINE_TIMER(_name, _function, _expires, _data) \struct timer_list _name \TIMER_INITIALIZER(_function, _expires, _data)2. 动态初始化-----手动对变量进行初始化 #define init_timer(timer) \do { \static struct lock_class_key __key; \init_timer_key((timer), #timer, __key); \} while (0)可延时定时 #define init_timer_deferrable(timer) \do { \static struct lock_class_key __key; \init_timer_deferrable_key((timer), #timer, __key); \} while (0)设置定时时间 #define setup_timer(timer, fn, data) \ do { \static struct lock_class_key __key; \setup_timer_key((timer), #timer, __key, (fn), (data));\ } while (0)向内核添加定时器: /*** add_timer - start a timer* timer: the timer to be added** The kernel will do a -function(-data) callback from the* timer interrupt at the -expires point in the future. The* current time is jiffies.** The timers -expires, -function (and if the handler uses it, -data)* fields must be set prior calling this function.** Timers with an -expires field in the past will be executed in the next* timer tick.*/ void add_timer(struct timer_list *timer) {BUG_ON(timer_pending(timer));mod_timer(timer, timer-expires); }从内核删除定时器 /*** del_timer - deactive a timer.* timer: the timer to be deactivated** del_timer() deactivates a timer - this works on both active and inactive* timers.** The function returns whether it has deactivated a pending timer or not.* (ie. del_timer() of an inactive timer returns 0, del_timer() of an* active timer returns 1.)*/ int del_timer(struct timer_list *timer)修改定时时间 /*** mod_timer - modify a timers timeout* timer: the timer to be modified* expires: new timeout in jiffies** mod_timer() is a more efficient way to update the expire field of an* active timer (if the timer is inactive it will be activated)** mod_timer(timer, expires) is equivalent to:** del_timer(timer); timer-expires expires; add_timer(timer);** Note that if there are multiple unserialized concurrent users of the* same timer, then mod_timer() is the only safe way to modify the timeout,* since add_timer() cannot modify an already running timer.** The function returns whether it has modified a pending timer or not.* (ie. mod_timer() of an inactive timer returns 0, mod_timer() of an* active timer returns 1.)*/ int mod_timer(struct timer_list *timer, unsigned long expires)jiffies和时间的转换 extern unsigned int jiffies_to_msecs(const unsigned long j); extern unsigned int jiffies_to_usecs(const unsigned long j); extern unsigned long msecs_to_jiffies(const unsigned int m); extern unsigned long usecs_to_jiffies(const unsigned int u);三使用步骤 1、向内核添加定时器 setup_timer();设置定时器add_timer();.2、解绑定时器 int del_timer(struct timer_list *timer)四实例代码 #include linux/timer.h #include linux/kernel.h #include linux/module.hstruct timer_list timer; void function(unsigned long data) {static int count0;printk(this is timer test:%d\n,count);mod_timer(timer,jiffies1*HZ); } static int __init timer_module_init(void) {timer.expires jiffies5*HZ;setup_timer(timer,function,0);add_timer(timer);return 0; } static void __exit timer_module_cleanup(void) {del_timer(timer); }module_init(timer_module_init); module_exit(timer_module_cleanup); MODULE_LICENSE(GPL);本文章仅供学习交流用禁止用作商业用途文中内容来水枂编辑如需转载请告知谢谢合作 微信公众号zhjj0729 微博文艺to青年
http://www.huolong8.cn/news/307723/

相关文章:

  • 东莞市住房建设部网站安卓优化大师新版
  • 单位做网站资料需要什么35岁学网站开发怎么样
  • 个人网站免费注册蓝色 宽屏 网站 模板
  • 营销型网站的建设网站建设团队定制
  • 长春建设网站公司哪家好干果坚果网站建设
  • 网站建设岗位主要做什么长三角旅游推广联盟
  • 盐城建站装修网站排名
  • 免费建立自己的网站空间c 网站开发简单实例
  • 站长推荐自动跳转导航入口dw网页设计免费模板
  • 网站哪家公司做的好wordpress显示分类文章
  • 泰州市做网站找客户去哪个平台
  • 小户型室内装修设计公司网站网站建设的总体目标是什么
  • 做网站的调查问卷互助平台网站制作
  • 招远市建设局网站raid管理网站开发
  • 十个app制作网站wordpress常量
  • 计算机程序设计网站开发宁波免费seo排名优化
  • 网页设计与网站开发方向wordpress网页图片加载很慢
  • 品牌型网站有哪些企业网站开发用什么语言写
  • 网站免费正能量软件下载视频电子产品定制开发
  • 中国五大门户网站成都房产网最新楼盘二手房信息
  • php能自己做网站吗qq企业邮箱注册申请
  • 企业网站建设前言东营网络科技有限公司
  • 做美容美发学校网站公司大型网站制作
  • 群辉怎么做网站网站建哪家好
  • 小程序 微网站网站建设 微信营销
  • 网站建设的主题快速的网站建设
  • 公司网站建设费怎么做账怎么做招投标网站
  • 如何做阿里巴巴免费网站最新新闻热点作文素材
  • 西安建筑网站学建网站要多久
  • 门户网站制作的公司行业网站建设收费明细