Chinaunix首页 | 论坛 | 博客
  • 博客访问: 144004
  • 博文数量: 26
  • 博客积分: 590
  • 博客等级: 中士
  • 技术积分: 430
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-19 15:26
文章存档

2012年(10)

2011年(16)

我的朋友

分类: LINUX

2011-12-31 16:23:32


struct list_head
{
struct list_head *next;
struct list_head *prev;

};

expires = jiffies + 5*HZ; 定时5秒,时间到后执行function函数,data是传递给该函数的参数。

struct timer_list
{
struct list_head entry;
unsigned long expires; 
void (*function)(unsigned long);
unsigned long data;
struct tvec_base *base;  
};

void init_timer(struct timer_list *timer);初始化定时器
void add_timer(struct timer_list *timer); 启动定时器
int del_timer(struct timer_list *timer);
在定时器超时前将它删除,当定时器超时后,系统自动将它删除。


如果对时间要求不是很精确的情况下可以这么做:
int delay_t = 5;
unsigned long jiffies_t = jiffies + delay_t * HZ;
while(jiffies >=jiffies_t)
{
do something!
}
阅读(1827) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~