内核延时函数和定时器

一内核延时函数: 

1.短延时:                        

void ndelay(unsignedlong nsecs);

Void udelay(unsigned long usecs);

Void mdelay(unsigned long msecs);

         前面三个函数都属于忙等延时,对于毫秒级以上的延时,内核提供了下面三个函数(可睡眠):

                                               Voidmsleep(unsigned int msecs);

                                               Unsignedlong msleep_interruptble(unsigned int msecs);//可被打断

                                               Voidssleep(unsigned int second);

2.长延时:

最直观的方法就是比较当前jiffies和目标jiffies(设置为当前jiffies加上时间间隔的jiffies)

         例:(注:这也是忙等)

                  Unsigned long delay = jiffies + 100;

                   While(time_before(jiffies,dealy));//将两个时间进行比较

                            注:Hz相当于1秒。

                   内核中还定义了time_after();

                            #define  time_before(a, b) time_after(b, a);

 

3.睡眠延时:

Schedule_timeout_uninterruptible(jiffies);

Schedule_timeout_interruptible(jiffies);

下面两个函数是将当前进程添加到等待队列中,从而再等待队列上睡眠,当超时发生时,进程将被唤醒:

                   Sleep_on_timeout(wait_queue_head_t*q, unsigned long timeout);

                   Interruptible_Sleep_on_timeout(wait_queue_head_t*q, unsigned long timeout);

 

二.内核定时器

                            见 书 203页。

转载地址:http://blog.csdn.net/wangyunqian6/article/details/6624117

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值