mirror of
https://github.com/libevent/libevent.git
synced 2025-01-31 09:12:55 +08:00
Expose our cached gettimeofday value with a new interface
I've got a two use case that wants this for a fairly sensible purpose: one external and on internal.
This commit is contained in:
parent
5a43df82b8
commit
47854a802a
16
event.c
16
event.c
@ -180,6 +180,22 @@ gettime(struct event_base *base, struct timeval *tp)
|
|||||||
return (evutil_gettimeofday(tp, NULL));
|
return (evutil_gettimeofday(tp, NULL));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
event_base_gettimeofday_cached(struct event_base *base, struct timeval *tv)
|
||||||
|
{
|
||||||
|
int r;
|
||||||
|
if (!base) {
|
||||||
|
base = current_base;
|
||||||
|
if (!current_base)
|
||||||
|
return evutil_gettimeofday(tv, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
EVBASE_ACQUIRE_LOCK(base, th_base_lock);
|
||||||
|
r = gettime(base, tv);
|
||||||
|
EVBASE_RELEASE_LOCK(base, th_base_lock);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
clear_time_cache(struct event_base *base)
|
clear_time_cache(struct event_base *base)
|
||||||
{
|
{
|
||||||
|
@ -671,6 +671,20 @@ void event_set_mem_functions(void *(*malloc_fn)(size_t sz),
|
|||||||
|
|
||||||
void event_base_dump_events(struct event_base *, FILE *);
|
void event_base_dump_events(struct event_base *, FILE *);
|
||||||
|
|
||||||
|
/** Sets 'tv' to the current time (as returned by gettimeofday()),
|
||||||
|
looking at the cached value in 'base' if possible, and calling
|
||||||
|
gettimeofday() or clock_gettime() as appropriate if there is no
|
||||||
|
cached time.
|
||||||
|
|
||||||
|
Generally, this value will only be cached while actually
|
||||||
|
processing event callbacks, and may be very inaccuate if your
|
||||||
|
callbacks take a long time to execute.
|
||||||
|
|
||||||
|
Returns 0 on success, negative on failure.
|
||||||
|
*/
|
||||||
|
int event_base_gettimeofday_cached(struct event_base *base,
|
||||||
|
struct timeval *tv);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user