Add an option to disable the timeval cache.

svn:r1518
This commit is contained in:
Nick Mathewson 2009-11-09 18:30:33 +00:00
parent 693c24ef9d
commit ab96b5f3f5
4 changed files with 29 additions and 9 deletions

View File

@ -40,7 +40,7 @@ Changes in 2.0.3-alpha:
o Add a new bufferevent_socket_connect_hostname() to encapsulate the resolve-then-connect operation.
o Build kqueue.c correctly on GNU/kFreeBSD platforms. Patch pulled upstream from Debian.
o Alternative queue-based timeout algorithm for programs that use a large number of timeouts with the same value.
o New event_base_config option to disable the timeval cache entirely.
Changes in 2.0.2-alpha:
o Add a new flag to bufferevents to make all callbacks automatically deferred.

View File

@ -181,6 +181,8 @@ struct event_base {
struct event_iocp_port *iocp;
#endif
enum event_base_config_flag flags;
/* Notify main thread to wake up break, etc. */
int th_notify_fd[2];
struct event th_notify;

28
event.c
View File

@ -180,6 +180,20 @@ gettime(struct event_base *base, struct timeval *tp)
return (evutil_gettimeofday(tp, NULL));
}
static inline void
clear_time_cache(struct event_base *base)
{
base->tv_cache.tv_sec = 0;
}
static inline void
update_time_cache(struct event_base *base)
{
base->tv_cache.tv_sec = 0;
if (!(base->flags & EVENT_BASE_FLAG_NO_CACHE_TIME))
gettime(base, &base->tv_cache);
}
struct event_base *
event_init(void)
{
@ -281,6 +295,8 @@ event_base_new_with_config(struct event_config *cfg)
event_deferred_cb_queue_init(&base->defer_queue);
base->defer_queue.notify_fn = notify_base_cbq_callback;
base->defer_queue.notify_arg = base;
if (cfg)
base->flags = cfg->flags;
evmap_io_initmap(&base->io);
evmap_signal_initmap(&base->sigmap);
@ -1054,8 +1070,7 @@ event_base_loop(struct event_base *base, int flags)
* as we invoke user callbacks. */
EVBASE_ACQUIRE_LOCK(base, EVTHREAD_WRITE, th_base_lock);
/* clear time cache */
base->tv_cache.tv_sec = 0;
clear_time_cache(base);
if (base->sig.ev_signal_added)
evsig_base = base;
@ -1099,14 +1114,14 @@ event_base_loop(struct event_base *base, int flags)
/* update last old time */
gettime(base, &base->event_tv);
/* clear time cache */
base->tv_cache.tv_sec = 0;
clear_time_cache(base);
res = evsel->dispatch(base, tv_p);
if (res == -1)
return (-1);
gettime(base, &base->tv_cache);
update_time_cache(base);
timeout_process(base);
@ -1118,8 +1133,7 @@ event_base_loop(struct event_base *base, int flags)
done = 1;
}
/* clear time cache */
base->tv_cache.tv_sec = 0;
clear_time_cache(base);
EVBASE_RELEASE_LOCK(base, EVTHREAD_WRITE, th_base_lock);

View File

@ -167,7 +167,11 @@ enum event_base_config_flag {
an event_base. */
EVENT_BASE_FLAG_IGNORE_ENV = 0x02,
/** Windows only: enable the IOCP dispatcher at startup */
EVENT_BASE_FLAG_STARTUP_IOCP = 0x04
EVENT_BASE_FLAG_STARTUP_IOCP = 0x04,
/** Instead of checking the current time every time the event loop is
ready to run timeout callbacks, check after each timeout callback.
*/
EVENT_BASE_FLAG_NO_CACHE_TIME = 0x08
};
/**