mirror of
https://github.com/cuberite/libevent.git
synced 2025-09-08 11:53:00 -04:00
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:
parent
c8953d1b48
commit
212533e4a1
16
event.c
16
event.c
@ -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)
|
||||||
{
|
{
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user