人生如逆旅,我亦是行人!江湖人称wsjjeremy.blog.chinaunix.net
ubuntuer
全部博文(930)
intern(3)
string(19)
正则表达式(5)
2011年(60)
2010年(220)
2009年(371)
2008年(279)
baocheng
nba76ers
renjian2
qq576709
mcn304
zibuyule
西农魔峰
曾德标
zhuqing_
shanck
tendy
moshangx
wb123456
smile124
hjshajsh
chenhong
bzhao
python16
分类: LINUX
2010-01-19 13:19:06
#include <linux/module.h>#include <linux/kernel.h>#include <linux/init.h>#include <linux/version.h>#include <linux/timer.h>#include <linux/jiffies.h>#include <linux/list.h>#include <linux/spinlock.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("wzt");#define SLEEP_TIME 2static struct timer_list my_timer;typedef struct list_test_struct { int count; struct list_head list;}node;struct list_head head_list;rwlock_t list_lock = RW_LOCK_UNLOCKED;unsigned int g_count = 0;void timer_test(unsigned long data){ node *tmp = (node *)data; printk("%5d", tmp->count); del_timer_sync(&my_timer); timer_init(SLEEP_TIME);}int timer_init(unsigned int seconds){ node *s = NULL; init_timer(&my_timer); s = (node *)kmalloc(sizeof(node), GFP_ATOMIC); if (!s) return 0; write_lock(&list_lock); s->count = g_count++; list_add_tail(&(s->list), &head_list); write_lock(&list_lock); my_timer.data = (unsigned long)s; my_timer.function = timer_test; my_timer.expires = jiffies + seconds * 1000; add_timer(&my_timer); return 0;}int test_timer_init(void){ INIT_LIST_HEAD(&head_list); timer_init(SLEEP_TIME); return 0;}void test_timer_exit(void){ del_timer_sync(&my_timer); printk("timer test exit.\n");}module_init(test_timer_init);module_exit(test_timer_exit);
上一篇:内核中得到当前时间
下一篇:VFS层拦截read/write file_operations函数
登录 注册