Merge branch 'maint-0.3.1'

This commit is contained in:
Nick Mathewson 2017-09-11 13:49:20 -04:00
commit 52c40330c8
2 changed files with 22 additions and 8 deletions

View File

@ -29,6 +29,8 @@
#include "orconfig.h" #include "orconfig.h"
#define TOR_TIMERS_PRIVATE
#include "compat.h" #include "compat.h"
#include "compat_libevent.h" #include "compat_libevent.h"
#include "timers.h" #include "timers.h"
@ -148,6 +150,21 @@ libevent_timer_reschedule(void)
event_add(global_timer_event, &d); event_add(global_timer_event, &d);
} }
/** Run the callback of every timer that has expired, based on the current
* output of monotime_get(). */
STATIC void
timers_run_pending(void)
{
monotime_t now;
monotime_get(&now);
timer_advance_to_cur_time(&now);
tor_timer_t *t;
while ((t = timeouts_get(global_timeouts))) {
t->callback.cb(t, t->callback.arg, &now);
}
}
/** /**
* Invoked when the libevent timer has expired: see which tor_timer_t events * Invoked when the libevent timer has expired: see which tor_timer_t events
* have fired, activate their callbacks, and reschedule the libevent timer. * have fired, activate their callbacks, and reschedule the libevent timer.
@ -159,14 +176,7 @@ libevent_timer_callback(evutil_socket_t fd, short what, void *arg)
(void)what; (void)what;
(void)arg; (void)arg;
monotime_t now; timers_run_pending();
monotime_get(&now);
timer_advance_to_cur_time(&now);
tor_timer_t *t;
while ((t = timeouts_get(global_timeouts))) {
t->callback.cb(t, t->callback.arg, &now);
}
libevent_timer_reschedule(); libevent_timer_reschedule();
} }

View File

@ -22,5 +22,9 @@ void timer_free(tor_timer_t *t);
void timers_initialize(void); void timers_initialize(void);
void timers_shutdown(void); void timers_shutdown(void);
#ifdef TOR_TIMERS_PRIVATE
STATIC void timers_run_pending(void);
#endif
#endif #endif