diff options
author | Qian Li <liqian.cs@gmail.com> | 2018-02-16 14:53:59 -0800 |
---|---|---|
committer | dormando <dormando@rydia.net> | 2018-02-19 22:34:52 -0800 |
commit | 1276ad27dd90043f7127ffcbb8d751c1141593dc (patch) | |
tree | d9322b4329b94c5bc4b3161e59ae418acdd5289e /thread.c | |
parent | 7141922a6188b00bc542b29c578506e0db52c9c7 (diff) | |
download | memcached-1276ad27dd90043f7127ffcbb8d751c1141593dc.tar.gz |
Replace event_init() with new API if detect newer version
If we detect libevent version >= 2.0.2-alpha, change to use
event_base_new_with_config() instead of obsolete event_init() for creating new
event base. Set config flag to EVENT_BASE_FLAG_NOLOCK to avoid lock/unlock
around every libevent operation.
For newer version of libevent, the event_init() API is deprecated and is
totally unsafe for multithreaded use. By using the new API, we can explicitly
disable/enable locking on the event_base.
Diffstat (limited to 'thread.c')
-rw-r--r-- | thread.c | 11 |
1 files changed, 11 insertions, 0 deletions
@@ -309,7 +309,16 @@ void accept_new_conns(const bool do_accept) { * Set up a thread's information. */ static void setup_thread(LIBEVENT_THREAD *me) { +#if defined(LIBEVENT_VERSION_NUMBER) && LIBEVENT_VERSION_NUMBER >= 0x02000101 + struct event_config *ev_config; + ev_config = event_config_new(); + event_config_set_flag(ev_config, EVENT_BASE_FLAG_NOLOCK); + me->base = event_base_new_with_config(ev_config); + event_config_free(ev_config); +#else me->base = event_init(); +#endif + if (! me->base) { fprintf(stderr, "Can't allocate event base\n"); exit(1); @@ -374,6 +383,8 @@ static void *worker_libevent(void *arg) { register_thread_initialized(); event_base_loop(me->base, 0); + + event_base_free(me->base); return NULL; } |