Commit a103b7e7 authored by Haijun Zhu's avatar Haijun Zhu Committed by Facebook Github Bot 5

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
parent ecf14e67
...@@ -145,6 +145,7 @@ EventBase::EventBase(bool enableTimeMeasurement) ...@@ -145,6 +145,7 @@ EventBase::EventBase(bool enableTimeMeasurement)
, observer_(nullptr) , observer_(nullptr)
, observerSampleCount_(0) , observerSampleCount_(0)
, executionObserver_(nullptr) { , executionObserver_(nullptr) {
struct event ev;
{ {
std::lock_guard<std::mutex> lock(libevent_mutex_); std::lock_guard<std::mutex> lock(libevent_mutex_);
...@@ -153,10 +154,16 @@ EventBase::EventBase(bool enableTimeMeasurement) ...@@ -153,10 +154,16 @@ EventBase::EventBase(bool enableTimeMeasurement)
// allowing examination of its value without an explicit reference here. // allowing examination of its value without an explicit reference here.
// If ev.ev_base is NULL, then event_init() must be called, otherwise // If ev.ev_base is NULL, then event_init() must be called, otherwise
// call event_base_new(). // call event_base_new().
struct event ev;
event_set(&ev, 0, 0, nullptr, nullptr); 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)) { if (UNLIKELY(evb_ == nullptr)) {
LOG(ERROR) << "EventBase(): Failed to init event base."; LOG(ERROR) << "EventBase(): Failed to init event base.";
folly::throwSystemError("error in EventBase::EventBase()"); folly::throwSystemError("error in EventBase::EventBase()");
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment