]> granicus.if.org Git - libevent/commitdiff
New event_base_update_cache_time() to set cached_tv to current time
authorAbel Mathew <abelpmathew@gmail.com>
Fri, 21 Oct 2011 19:53:32 +0000 (19:53 +0000)
committerNick Mathewson <nickm@torproject.org>
Fri, 21 Oct 2011 22:08:08 +0000 (18:08 -0400)
This function is particularly useful for selectively increasing
the accuracy of the cached time value in 'base' during callbacks
that take a long time to execute.

This function has no effect if the base is currently not in its
event loop or if timeval caching is disabled via EVENT_BASE_FLAG_NO_CACHE_TIME.

event.c
include/event2/event.h

diff --git a/event.c b/event.c
index 16b17c196b77d26bee092066658f5278fec6f786..8c04f547991396daf957df2fce37b6364d3b4a19 100644 (file)
--- a/event.c
+++ b/event.c
@@ -435,6 +435,22 @@ update_time_cache(struct event_base *base)
            gettime(base, &base->tv_cache);
 }
 
+int
+event_base_update_cache_time(struct event_base *base)
+{
+
+       if (!base) {
+               base = current_base;
+               if (!current_base)
+                       return -1;
+       }
+
+       EVBASE_ACQUIRE_LOCK(base, th_base_lock);
+       update_time_cache(base);
+       EVBASE_RELEASE_LOCK(base, th_base_lock);
+       return 0;
+}
+
 struct event_base *
 event_init(void)
 {
index 122eec0821d2a1c29f230455f86dcb9d47eee1c6..cccb5fd96c3307e6d13b68323e342fed8df226a1 100644 (file)
@@ -1255,6 +1255,20 @@ void event_base_dump_events(struct event_base *, FILE *);
 int event_base_gettimeofday_cached(struct event_base *base,
     struct timeval *tv);
 
+/** Update cached_tv in the 'base' to the current time
+ *
+ * You can use this function is useful for selectively increasing
+ * the accuracy of the cached time value in 'base' during callbacks
+ * that take a long time to execute.
+ *
+ * This function has no effect if the base is currently not in its
+ * event loop, or if timeval caching is disabled via
+ * EVENT_BASE_FLAG_NO_CACHE_TIME.
+ *
+ * @return 0 on success, -1 on failure
+ */
+int event_base_update_cache_time(struct event_base *base);
+
 #ifdef __cplusplus
 }
 #endif