?current->timeout=j; ?current->state=TASK_INTERRUPTIBLE; ?schedule(); ?current->timeout=0;/* 重置timeout 值*/
#include <linux/timer.h> struct timer_list { struct timer_list *next; /*不要直接修改它 */ struct timer_list *prev; /*不要直接修改它 */ unsigned long expires; /* timeout 超时值,以jiffies 值为单位 */ unsigned long data; /* 传递给定时器处理程序的参数 */ void (*function)(unsigned long); /* 超时时调用的定时器处理程序 */ }; #define TIMER_INITIALIZER(_function, _expires, _data)
void init_timer(struct timer_list *timer); void add_timer(struct timer_list * timer); 初始化完timer_list 结构,add_timer函数就将它插入一张有序表中. int del_timer(struct timer_list * timer); 如果需要在定时器超时前将它从列表中删除,应调用del_timer 函数.但当定时器超时时,系统会自动地将它从列表中删除. int mod_timer(struct timer_list *timer, unsigned long expires) 修改timer, 相当于 del_timer(timer); timer->expires = expires; add_timer(timer); 的操作 <span style="color:#FF0000;"><strong>但是, 在考虑并发的情况下, mod_timer才是修改timeout的安全的方法, 因为add_timer不能去修改一个正在running的timer.</strong></span> Note: 定时器中断是软中断
#include <linux/interrupt.h> struct tasklet_struct { struct tasklet_struct *next; unsigned long state; atomic_t count; void (*func)(unsigned long); unsigned long data; }
#include <linux/workqueue.h> struct work_struct { struct cpu_workqueue_struct *cpu_wq; struct list_head list; const char *name; int singlethread; int freezeable; /* Freeze threads during suspend */ #ifdef CONFIG_LOCKDEP struct lockdep_map lockdep_map; #endif };
原文地址:http://blog.csdn.net/jackjones_008/article/details/42295411