From 3c63edd1f7ea1e26937466cf3ad16b7bf0e265e4 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 11 Aug 2011 12:47:21 -0400 Subject: [PATCH] Make the priority inversion code use gettime(), not evutil_gettimeofday() Since we're computing the time after each callback, we might as well update the time cache (if we're using it) and use monotonic time (if we've got that). --- defer-internal.h | 4 ++++ event.c | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/defer-internal.h b/defer-internal.h index 1892c556..68fe8851 100644 --- a/defer-internal.h +++ b/defer-internal.h @@ -57,6 +57,10 @@ struct deferred_cb_queue { /** Lock used to protect the queue. */ void *lock; + /** Which event_base does this queue associate itself with? + * (Used for timing) */ + struct event_base *base; + /** How many entries are in the queue? */ int active_count; diff --git a/event.c b/event.c index 233e8897..2ef61e9f 100644 --- a/event.c +++ b/event.c @@ -573,6 +573,7 @@ event_base_new_with_config(const struct event_config *cfg) base->th_notify_fd[1] = -1; event_deferred_cb_queue_init(&base->defer_queue); + base->defer_queue.base = base; base->defer_queue.notify_fn = notify_base_cbq_callback; base->defer_queue.notify_arg = base; if (cfg) @@ -1376,7 +1377,8 @@ event_process_active_single_queue(struct event_base *base, return count; if (count && endtime) { struct timeval now; - evutil_gettimeofday(&now, NULL); + update_time_cache(base); + gettime(base, &now); if (evutil_timercmp(&now, endtime, >=)) return count; } @@ -1416,7 +1418,8 @@ event_process_deferred_callbacks(struct deferred_cb_queue *queue, int *breakptr, break; if (endtime) { struct timeval now; - evutil_gettimeofday(&now, NULL); + update_time_cache(queue->base); + gettime(queue->base, &now); if (evutil_timercmp(&now, endtime, >=)) return count; } @@ -1441,7 +1444,8 @@ event_process_active(struct event_base *base) const int maxcb = base->max_dispatch_callbacks; const int limit_after_prio = base->limit_callbacks_after_prio; if (base->max_dispatch_time.tv_sec >= 0) { - evutil_gettimeofday(&tv, NULL); + update_time_cache(base); + gettime(base, &tv); evutil_timeradd(&base->max_dispatch_time, &tv, &tv); endtime = &tv; } else {