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);
mainloop_event_t * mainloop_event_new(void(*cb)(mainloop_event_t *, void *), void *userdata)
int mainloop_event_schedule(mainloop_event_t *event, const struct timeval *tv)
Header for compat_libevent.c.
int64_t monotime_diff_usec(const monotime_t *start, const monotime_t *end)
Functions and types for monotonic times.
void monotime_get(monotime_t *out)
Headers for util_malloc.c.
static void libevent_timer_callback(mainloop_event_t *ev, void *arg)
static void libevent_timer_reschedule(void)
static void timer_advance_to_cur_time(const monotime_t *now)
void timer_set_cb(tor_timer_t *t, timer_cb_fn_t cb, void *arg)
void timer_schedule(tor_timer_t *t, const struct timeval *tv)
void timer_get_cb(const tor_timer_t *t, timer_cb_fn_t *cb_out, void **arg_out)
static timeout_t tv_to_timeout(const struct timeval *tv)
void timers_shutdown(void)
void timers_initialize(void)
tor_timer_t * timer_new(timer_cb_fn_t cb, void *arg)
void timer_disable(tor_timer_t *t)
static void timeout_to_tv(timeout_t t, struct timeval *tv_out)
STATIC void timers_run_pending(void)
void timer_free_(tor_timer_t *t)
Macros to manage assertions, fatal and non-fatal.