-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.h
More file actions
61 lines (49 loc) · 1.16 KB
/
timer.h
File metadata and controls
61 lines (49 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef _TIMER_H_
#define _TIMER_H_
#ifdef __cplusplus
extern "C" { /* C++ will be happy */
#endif
/*
* Using only a single timer (either alarm or the higher-precision setitimer),
* provide a set of fuctions that allows a process to set any number of timers.
*
* 用一个alarm闹钟实现管理多个定时任务的闹钟
*/
/*
* 类型定义:Timer标识类型, Timer类型
*/
typedef long TimerId_t;
#define ADD_FAILED ((TimerId_t)(-1))
enum TimerType {
LOOP, /* 循环型闹钟 */
ONCE, /* 一次性闹钟 */
/*
... 其他类型
*/
};
/**
* 初始化Timer,成功返回0,失败返回-1
*/
int timer_init(void);
/**
* 添加Timer,成功返回新添加的Timer标识,失败返回ADD_FAILED
* @sec: Timer触发的时间间隔
* @task: 绑定Timer的任务
* @arg: 任务传参
* @type: Timer类型
*/
typedef void Task_t(void *);
TimerId_t timer_add(int sec, Task_t *task, void *arg, enum TimerType type);
/**
* 删除指定的闹钟
* @id:闹钟标识
*/
void timer_del(TimerId_t id);
/**
* 销毁所有闹钟
*/
void timer_destroy(void);
#ifdef __cplusplus
}
#endif
#endif //_TIMER_H_