diff --git a/event.c b/event.c index 16b17c19..8c04f547 100644 --- 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) { diff --git a/include/event2/event.h b/include/event2/event.h index 122eec08..cccb5fd9 100644 --- a/include/event2/event.h +++ b/include/event2/event.h @@ -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