From: Haijun Zhu Date: Sun, 27 Mar 2016 07:12:23 +0000 (-0700) Subject: Move event_base_new out of critical region X-Git-Tag: 2016.07.26~410 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=a103b7e715d824b770c11e9106a4d5ec1ee448cf;p=folly.git Move event_base_new out of critical region Summary:event_base_new does not change the global current_base so no need to call it with the mutex held. Reviewed By: chadparry Differential Revision: D3055963 fb-gh-sync-id: df420b189ef0d7d56eda5ad6c32e03b195804e6b fbshipit-source-id: df420b189ef0d7d56eda5ad6c32e03b195804e6b --- diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index e51fb08f..5dcc9967 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -145,6 +145,7 @@ EventBase::EventBase(bool enableTimeMeasurement) , observer_(nullptr) , observerSampleCount_(0) , executionObserver_(nullptr) { + struct event ev; { std::lock_guard lock(libevent_mutex_); @@ -153,10 +154,16 @@ EventBase::EventBase(bool enableTimeMeasurement) // allowing examination of its value without an explicit reference here. // If ev.ev_base is NULL, then event_init() must be called, otherwise // call event_base_new(). - struct event ev; event_set(&ev, 0, 0, nullptr, nullptr); - evb_ = (ev.ev_base) ? event_base_new() : event_init(); + if (!ev.ev_base) { + evb_ = event_init(); + } + } + + if (ev.ev_base) { + evb_ = event_base_new(); } + if (UNLIKELY(evb_ == nullptr)) { LOG(ERROR) << "EventBase(): Failed to init event base."; folly::throwSystemError("error in EventBase::EventBase()");