34 #include "ext/tor_queue.h"
42 #if !defined TIMEOUT_PUBLIC
43 #define TIMEOUT_PUBLIC
46 #define TIMEOUT_VERSION TIMEOUT_V_REL
47 #define TIMEOUT_VENDOR "william@25thandClement.com"
49 #define TIMEOUT_V_REL 0x20160226
50 #define TIMEOUT_V_ABI 0x20160224
51 #define TIMEOUT_V_API 0x20160226
53 TIMEOUT_PUBLIC
int timeout_version(
void);
55 TIMEOUT_PUBLIC
const char *timeout_vendor(
void);
57 TIMEOUT_PUBLIC
int timeout_v_rel(
void);
59 TIMEOUT_PUBLIC
int timeout_v_abi(
void);
61 TIMEOUT_PUBLIC
int timeout_v_api(
void);
69 #define TIMEOUT_C(n) UINT64_C(n)
70 #define TIMEOUT_PRIu PRIu64
71 #define TIMEOUT_PRIx PRIx64
72 #define TIMEOUT_PRIX PRIX64
74 #define TIMEOUT_mHZ TIMEOUT_C(1000)
75 #define TIMEOUT_uHZ TIMEOUT_C(1000000)
76 #define TIMEOUT_nHZ TIMEOUT_C(1000000000)
78 typedef uint64_t timeout_t;
80 #define timeout_error_t int
91 #ifndef TIMEOUT_CB_OVERRIDE
103 #ifndef TIMEOUT_DISABLE_INTERVALS
104 #define TIMEOUT_INT 0x01
106 #define TIMEOUT_ABS 0x02
108 #define TIMEOUT_INITIALIZER(flags) { (flags) }
110 #define timeout_setcb(to, fn, arg) do { \
111 (to)->callback.fn = (fn); \
112 (to)->callback.arg = (arg); \
121 struct timeout_list *pending;
127 #ifndef TIMEOUT_DISABLE_CALLBACKS
132 #ifndef TIMEOUT_DISABLE_INTERVALS
137 #ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS
144 TIMEOUT_PUBLIC
struct timeout *timeout_init(
struct timeout *,
int);
147 #ifndef TIMEOUT_DISABLE_RELATIVE_ACCESS
148 TIMEOUT_PUBLIC
bool timeout_pending(
struct timeout *);
151 TIMEOUT_PUBLIC
bool timeout_expired(
struct timeout *);
154 TIMEOUT_PUBLIC
void timeout_del(
struct timeout *);
165 TIMEOUT_PUBLIC
struct timeouts *timeouts_open(timeout_t, timeout_error_t *);
168 TIMEOUT_PUBLIC
void timeouts_close(
struct timeouts *);
171 TIMEOUT_PUBLIC timeout_t timeouts_hz(
struct timeouts *);
174 TIMEOUT_PUBLIC
void timeouts_update(
struct timeouts *, timeout_t);
177 TIMEOUT_PUBLIC
void timeouts_step(
struct timeouts *, timeout_t);
180 TIMEOUT_PUBLIC timeout_t timeouts_get_curtime(
struct timeouts *);
183 TIMEOUT_PUBLIC timeout_t timeouts_timeout(
struct timeouts *);
186 TIMEOUT_PUBLIC
void timeouts_add(
struct timeouts *,
struct timeout *, timeout_t);
195 TIMEOUT_PUBLIC
bool timeouts_pending(
struct timeouts *);
198 TIMEOUT_PUBLIC
bool timeouts_expired(
struct timeouts *);
201 TIMEOUT_PUBLIC
bool timeouts_check(
struct timeouts *, FILE *);
204 #define TIMEOUTS_PENDING 0x10
205 #define TIMEOUTS_EXPIRED 0x20
206 #define TIMEOUTS_ALL (TIMEOUTS_PENDING|TIMEOUTS_EXPIRED)
207 #define TIMEOUTS_CLEAR 0x40
209 #define TIMEOUTS_IT_INITIALIZER(flags) { (flags), 0, 0, 0, 0 }
211 #define TIMEOUTS_IT_INIT(cur, _flags) do { \
212 (cur)->flags = (_flags); \
229 #define TIMEOUTS_FOREACH(var, T, flags) \
230 struct timeouts_it _it = TIMEOUTS_IT_INITIALIZER((flags)); \
231 while (((var) = timeouts_next((T), &_it)))
247 #define timeouts_f2i(T, f) \
248 ((timeout_t)ceil((f) * timeouts_hz((T))))
250 #define timeouts_i2f(T, i) \
251 ((double)(i) / timeouts_hz((T)))
253 #define timeouts_addf(T, to, timeout) \
254 timeouts_add((T), (to), timeouts_f2i((T), (timeout)))