linux编程 定时器,Linux 定时器编程

linux编程 定时器,Linux 定时器编程二、内核定时器用到的数据结构structtimer_list{structlist_headentry;unsignedlongexpires;//定时器时间设置一般为jiffies+n(0void(*function)(unsignedlong);//定时器处理函数unsignedlongdata;//定时器私有数据structtvec_base*base;#ifde…

二、内核定时器

用到的数据结构

struct timer_list {

struct list_head entry;

unsigned long expires;//定时器时间设置一般为jiffies + n(0

void (*function)(unsigned long);//定时器处理函数

unsigned long data;//定时器私有数据

struct tvec_base *base;

#ifdef CONFIG_TIMER_STATS

void *start_site;

char start_comm[16];

int start_pid;

#endif

#ifdef CONFIG_LOCKDEP

struct lockdep_map lockdep_map;

#endif

};

用到的函数:

#define init_timer(timer) init_timer_key((timer), NULL, NULL)

void init_timer_key(struct timer_list *timer,

const char *name,

struct lock_class_key *key)

{

debug_init(timer);

__init_timer(timer, name, key);

}

初始化一个定时器

void add_timer(struct timer_list *timer)

{

BUG_ON(timer_pending(timer));

mod_timer(timer, timer->expires);

}

该函数用于添加一个定时器

代码如下:

#include 

#include 

#include

#include

strcut timer_list timed;

static void exec_timer(unsigned long arg)

{

printf(“do someting else\n”);

timed.expires = jiffies + 128;

add_timer(&timed);//再次添加一个定时器

}

static int xx_init()

{

init_timer(&time);

timed.function = exec_timer;

timed.expires = jiffies + 128;

timed.data = (unsigned long)xx_datap;

}0b1331709591d260c1c78e86d0c51c18.png

今天的文章linux编程 定时器,Linux 定时器编程分享到此就结束了,感谢您的阅读。

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
如需转载请保留出处:http://bianchenghao.cn/13296.html

(0)
编程小号编程小号

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注