-
Notifications
You must be signed in to change notification settings - Fork 86
/
Copy pathre_tmr.h
93 lines (79 loc) · 2.35 KB
/
re_tmr.h
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
* @file re_tmr.h Interface to timer implementation
*
* Copyright (C) 2010 Creytiv.com
*/
#include "re_thread.h"
#include "re_atomic.h"
/**
* Defines the timeout handler
*
* @param arg Handler argument
*/
typedef void (tmr_h)(void *arg);
struct tmrl;
/** Defines a timer */
struct tmr {
struct le le; /**< Linked list element */
RE_ATOMIC bool active; /**< Timer is active */
mtx_t *llock; /**< List Mutex lock */
tmr_h *th; /**< Timeout handler */
void *arg; /**< Handler argument */
uint64_t jfs; /**< Jiffies for timeout */
const char *file;
int line;
};
#define TMR_INIT {.le = LE_INIT}
int tmrl_alloc(struct tmrl **tmrl);
void tmr_poll(struct tmrl *tmrl);
uint64_t tmr_jiffies_usec(void);
uint64_t tmr_jiffies(void);
uint64_t tmr_jiffies_rt_usec(void);
int tmr_timespec_get(struct timespec *tp, uint64_t offset);
uint64_t tmr_next_timeout(struct tmrl *tmrl);
void tmr_debug(void);
int tmr_status(struct re_printf *pf, void *unused);
void tmr_init(struct tmr *tmr);
void tmr_start_dbg(struct tmr *tmr, uint64_t delay, tmr_h *th, void *arg,
const char *file, int line);
void tmr_continue_dbg(struct tmr *tmr, uint64_t delay,
tmr_h *th, void *arg,
const char *file, int line);
uint32_t tmrl_count(struct tmrl *tmrl);
/**
* @def tmr_start(tmr, delay, th, arg)
*
* Start a timer
*
* @param tmr Timer to start
* @param delay Timer delay in [ms]
* @param th Timeout handler
* @param arg Handler argument
*/
#define tmr_start(tmr, delay, th, arg) \
tmr_start_dbg(tmr, delay, th, arg, __FILE__, __LINE__)
/**
* @def tmr_continue(tmr, delay, th, arg)
*
* Continue a previously started timer with exactly added delay
*
* @param tmr Timer to start
* @param delay Timer delay in [ms]
* @param th Timeout handler
* @param arg Handler argument
*/
#define tmr_continue(tmr, delay, th, arg) \
tmr_continue_dbg(tmr, delay, th, arg, __FILE__, __LINE__)
void tmr_cancel(struct tmr *tmr);
uint64_t tmr_get_expire(const struct tmr *tmr);
/**
* Check if the timer is running
*
* @param tmr Timer to check
*
* @return true if running, false if not running
*/
static inline bool tmr_isrunning(const struct tmr *tmr)
{
return tmr ? NULL != tmr->th : false;
}