New event_base_update_cache_time() to set cached_tv to current time

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.
This commit is contained in:
Abel Mathew 2011-10-21 19:53:32 +00:00 committed by Nick Mathewson
parent c8953d1b48
commit 212533e4a1
2 changed files with 30 additions and 0 deletions

16
event.c
View File

@ -435,6 +435,22 @@ update_time_cache(struct event_base *base)
gettime(base, &base->tv_cache); 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 * struct event_base *
event_init(void) event_init(void)
{ {

View File

@ -1255,6 +1255,20 @@ void event_base_dump_events(struct event_base *, FILE *);
int event_base_gettimeofday_cached(struct event_base *base, int event_base_gettimeofday_cached(struct event_base *base,
struct timeval *tv); 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 #ifdef __cplusplus
} }
#endif #endif