From c612ddee17c2f6e70fde9f0bdd7116516f384ae8 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 28 Sep 2010 14:01:45 -0400 Subject: Add a new option to enable/disable IOCP support --- src/common/compat_libevent.c | 18 ++++++++++++++++-- src/common/compat_libevent.h | 7 ++++++- 2 files changed, 22 insertions(+), 3 deletions(-) (limited to 'src/common') diff --git a/src/common/compat_libevent.c b/src/common/compat_libevent.c index bbab06e8d4..6afd3c1d29 100644 --- a/src/common/compat_libevent.c +++ b/src/common/compat_libevent.c @@ -159,7 +159,7 @@ struct event_base *the_event_base = NULL; /** Initialize the Libevent library and set up the event base. */ void -tor_libevent_initialize(void) +tor_libevent_initialize(tor_libevent_cfg *torcfg) { tor_assert(the_event_base == NULL); @@ -171,7 +171,21 @@ tor_libevent_initialize(void) #endif #ifdef HAVE_EVENT2_EVENT_H - the_event_base = event_base_new(); + { + struct event_config *cfg = event_config_new(); + +#if defined(MS_WINDOWS) && defined(USE_BUFFEREVENTS) + if (! torcfg->disable_iocp) + event_config_set_flag(cfg, EVENT_BASE_FLAG_STARTUP_IOCP); +#endif + +#if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= V(2,0,7) + if (torcfg->num_cpus > 0) + event_config_set_num_cpus_hint(cfg, torcfg->num_cpus); +#endif + + the_event_base = event_base_new_with_config(cfg); + } #else the_event_base = event_init(); #endif diff --git a/src/common/compat_libevent.h b/src/common/compat_libevent.h index f483d6ee6d..ecf25806d5 100644 --- a/src/common/compat_libevent.h +++ b/src/common/compat_libevent.h @@ -56,7 +56,12 @@ struct timeval; int tor_event_base_loopexit(struct event_base *base, struct timeval *tv); #endif -void tor_libevent_initialize(void); +typedef struct tor_libevent_cfg { + int disable_iocp; + int num_cpus; +} tor_libevent_cfg; + +void tor_libevent_initialize(tor_libevent_cfg *cfg); struct event_base *tor_libevent_get_base(void); const char *tor_libevent_get_method(void); void tor_check_libevent_version(const char *m, int server, -- cgit v1.2.3-54-g00ecf