32 #define TOR_TIMERS_PRIVATE
42 #ifdef HAVE_SYS_TIME_H
60 #define TIMEOUT_PUBLIC
61 #elif defined(__GNUC__)
63 #define TIMEOUT_PUBLIC __attribute__((__unused__)) static
66 #define TIMEOUT_PUBLIC static
69 #define TIMEOUT_DISABLE_INTERVALS
72 #define TIMEOUT_DISABLE_RELATIVE_ACCESS
74 #define TIMEOUT_CB_OVERRIDE
80 #if SIZEOF_VOID_P == 4
86 #include "ext/timeouts/timeout.c"
88 static struct timeouts *global_timeouts = NULL;
101 #define USEC_PER_TICK 100
104 #define USEC_PER_SEC 1000000
107 #define MIN_CHECK_SECONDS 3600
110 #define MIN_CHECK_TICKS \
111 (((timeout_t)MIN_CHECK_SECONDS) * (1000000 / USEC_PER_TICK))
122 uint64_t usec = tv->tv_usec;
147 timeouts_update(global_timeouts, cur_tick);
161 timeout_t delay = timeouts_timeout(global_timeouts);
180 while ((t = timeouts_get(global_timeouts))) {
181 t->callback.cb(t, t->callback.arg, &now);
207 if (BUG(global_timeouts))
210 timeout_error_t err = 0;
211 global_timeouts = timeouts_open(0, &err);
212 if (!global_timeouts) {
214 log_err(
LD_BUG,
"Unable to open timer backend: %s", strerror(err));
225 global_timer_event = timer_event;
236 if (global_timer_event) {
237 mainloop_event_free(global_timer_event);
238 global_timer_event = NULL;
240 if (global_timeouts) {
241 timeouts_close(global_timeouts);
242 global_timeouts = NULL;
252 tor_timer_t *t = tor_malloc(
sizeof(tor_timer_t));
268 timeouts_del(global_timeouts, t);
279 t->callback.arg = arg;
288 timer_cb_fn_t *cb_out,
void **arg_out)
291 *cb_out = t->callback.cb;
293 *arg_out = t->callback.arg;
310 timeout_t to = timeouts_timeout(global_timeouts);
312 timeouts_add(global_timeouts, t, delay);
328 timeouts_del(global_timeouts, t);