📄 timer.h.txt
字号:
any question,send email to netxiong@263.net
相关文件
/kernel/timer.c
****************************基本数据结构*********************************************
#define TVN_BITS 6
#define TVR_BITS 8
#define TVN_SIZE (1 << TVN_BITS)
#define TVR_SIZE (1 << TVR_BITS)
#define TVN_MASK (TVN_SIZE - 1)
#define TVR_MASK (TVR_SIZE - 1) //?????
typedef struct tvec_s {
int index;
struct list_head vec[TVN_SIZE]; //等待队列的元素就挂接到后面。
} tvec_t;
这里的挂结地点是一个数组,具体挂接到那一个节点上有add_timer来定。
typedef struct tvec_root_s { //和tvec_s一样。
int index;
struct list_head vec[TVR_SIZE];
} tvec_root_t;
typedef struct tvec_t_base_s {
spinlock_t lock;
unsigned long timer_jiffies;
volatile timer_t * volatile running_timer; //?
tvec_root_t tv1; //等待处理的timer队列
tvec_t tv2; //等待处理的timer队列
tvec_t tv3; //……
tvec_t tv4; //……
tvec_t tv5; //……
} tvec_base_t;
没一个cpu都有这么一个结构对应,其中的tv1,tv2,tv3,tv4,tv5这些都是可以挂结timer的等待队列的结构。
struct timer_list {
struct list_head list; //双向链表
unsigned long expires; //需要处理的时间
unsigned long data; //参数
void (*function)(unsigned long); //处理函数
tvec_base_t *base; //挂结的头节点。
};
这个结构就是要挂接到timer队列中的结构。
tvec_base_t
tvec_t
vec[]
tvec_root_t
(list)vec[]------>timer_list<--------------------------|
list-------->timer_list |
expires list----------
function expires
function
************************************************************************************
**************************基本函数**************************************************
(1):static inline void init_timer(timer_t * timer)
#初始化一个timer
timer->list.next = timer->list.prev = NULL;
timer->base = tvec_bases + 0;
(2):static inline int timer_pending(const timer_t * timer)
#检查timer是否是和其他的timer无连接
return timer->list.next != NULL;
************************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -