]> granicus.if.org Git - libevent/commitdiff
Add an option to disable the timeval cache.
authorNick Mathewson <nickm@torproject.org>
Mon, 9 Nov 2009 18:30:33 +0000 (18:30 +0000)
committerNick Mathewson <nickm@torproject.org>
Mon, 9 Nov 2009 18:30:33 +0000 (18:30 +0000)
svn:r1518

ChangeLog
event-internal.h
event.c
include/event2/event.h

index b06128feb1169613d260b172fe1e8a143910d76e..c720db76add4b9cb8532cdf54317b1dc96bbf872 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -40,7 +40,7 @@ Changes in 2.0.3-alpha:
  o Add a new bufferevent_socket_connect_hostname() to encapsulate the resolve-then-connect operation.
  o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian.
  o Alternative queue-based timeout algorithm for programs that use a large number of timeouts with the same value.
-
+ o New event_base_config option to disable the timeval cache entirely.
 
 Changes in 2.0.2-alpha:
  o Add a new flag to bufferevents to make all callbacks automatically deferred.
index 662e23d61b9b52530fd25b5e0869467c25a0c5b5..4fef73c13f42d5c6c0c186b37fcdac92bf4d4ebf 100644 (file)
@@ -181,6 +181,8 @@ struct event_base {
        struct event_iocp_port *iocp;
 #endif
 
+        enum event_base_config_flag flags;
+
        /* Notify main thread to wake up break, etc. */
        int th_notify_fd[2];
        struct event th_notify;
diff --git a/event.c b/event.c
index 2f1a8429b8e068d813c36c51c00962a3040bf639..327546e222046074f9780df150346ace2b4375be 100644 (file)
--- a/event.c
+++ b/event.c
@@ -180,6 +180,20 @@ gettime(struct event_base *base, struct timeval *tp)
        return (evutil_gettimeofday(tp, NULL));
 }
 
+static inline void
+clear_time_cache(struct event_base *base)
+{
+       base->tv_cache.tv_sec = 0;
+}
+
+static inline void
+update_time_cache(struct event_base *base)
+{
+       base->tv_cache.tv_sec = 0;
+       if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME))
+           gettime(base, &base->tv_cache);
+}
+
 struct event_base *
 event_init(void)
 {
@@ -281,6 +295,8 @@ event_base_new_with_config(struct event_config *cfg)
        event_deferred_cb_queue_init(&base->defer_queue);
        base->defer_queue.notify_fn = notify_base_cbq_callback;
        base->defer_queue.notify_arg = base;
+       if (cfg)
+               base->flags = cfg->flags;
 
        evmap_io_initmap(&base->io);
        evmap_signal_initmap(&base->sigmap);
@@ -1054,8 +1070,7 @@ event_base_loop(struct event_base *base, int flags)
         * as we invoke user callbacks. */
        EVBASE_ACQUIRE_LOCK(base, EVTHREAD_WRITE, th_base_lock);
 
-       /* clear time cache */
-       base->tv_cache.tv_sec = 0;
+       clear_time_cache(base);
 
        if (base->sig.ev_signal_added)
                evsig_base = base;
@@ -1099,14 +1114,14 @@ event_base_loop(struct event_base *base, int flags)
                /* update last old time */
                gettime(base, &base->event_tv);
 
-               /* clear time cache */
-               base->tv_cache.tv_sec = 0;
+               clear_time_cache(base);
 
                res = evsel->dispatch(base, tv_p);
 
                if (res == -1)
                        return (-1);
-               gettime(base, &base->tv_cache);
+
+               update_time_cache(base);
 
                timeout_process(base);
 
@@ -1118,8 +1133,7 @@ event_base_loop(struct event_base *base, int flags)
                        done = 1;
        }
 
-       /* clear time cache */
-       base->tv_cache.tv_sec = 0;
+       clear_time_cache(base);
 
        EVBASE_RELEASE_LOCK(base, EVTHREAD_WRITE, th_base_lock);
 
index 4cc9bff89a9cbcf1d3c6aefca962c8d9c83f11b5..7fe6dc730a45a06b78a2b6db23b9be5b70b89296 100644 (file)
@@ -167,7 +167,11 @@ enum event_base_config_flag {
            an event_base. */
        EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
        /** Windows only: enable the IOCP dispatcher at startup */
-       EVENT_BASE_FLAG_STARTUP_IOCP = 0x04
+       EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
+       /** Instead of checking the current time every time the event loop is
+           ready to run timeout callbacks, check after each timeout callback.
+        */
+       EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08
 };
 
 /**