From: Pingjia Shan Date: Sun, 19 Nov 2017 05:55:44 +0000 (-0800) Subject: get rid of redundant calls to RequestContext::saveContext() X-Git-Tag: v2017.11.20.00~2 X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=commitdiff_plain;h=aa7f8dcd47b82f753862919d3456a961b30c0ab4 get rid of redundant calls to RequestContext::saveContext() Summary: In the past, these calls were required. Used to solve static destruction ordering issue. Any static object that uses RequestContext must call this function in its constructor. That is when we were using `static folly::ThreadLocal>`, which was non-leaky. The problem being addressed is when we have some code of the form: ```lang=c++ void doWork() { static EventBase eb; } ``` But now we are using `SingletonThreadLocal>`, which is leaky. So the issue that these calls were there to address seems to have been resolved. Reviewed By: yfeldblum Differential Revision: D6332597 fbshipit-source-id: c6aba6620ef2fb3a344ea20f56c8b9c0cdf42c70 --- diff --git a/folly/io/async/AsyncTimeout.cpp b/folly/io/async/AsyncTimeout.cpp index f08b7771..680d64c1 100644 --- a/folly/io/async/AsyncTimeout.cpp +++ b/folly/io/async/AsyncTimeout.cpp @@ -33,7 +33,6 @@ AsyncTimeout::AsyncTimeout(TimeoutManager* timeoutManager) timeoutManager_->attachTimeoutManager( this, TimeoutManager::InternalEnum::NORMAL); - RequestContext::saveContext(); } AsyncTimeout::AsyncTimeout(EventBase* eventBase) @@ -47,7 +46,6 @@ AsyncTimeout::AsyncTimeout(EventBase* eventBase) this, TimeoutManager::InternalEnum::NORMAL); } - RequestContext::saveContext(); } AsyncTimeout::AsyncTimeout(TimeoutManager* timeoutManager, @@ -58,7 +56,6 @@ AsyncTimeout::AsyncTimeout(TimeoutManager* timeoutManager, &event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this); event_.ev_base = nullptr; timeoutManager_->attachTimeoutManager(this, internal); - RequestContext::saveContext(); } AsyncTimeout::AsyncTimeout(EventBase* eventBase, InternalEnum internal) @@ -68,14 +65,12 @@ AsyncTimeout::AsyncTimeout(EventBase* eventBase, InternalEnum internal) &event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this); event_.ev_base = nullptr; timeoutManager_->attachTimeoutManager(this, internal); - RequestContext::saveContext(); } AsyncTimeout::AsyncTimeout(): timeoutManager_(nullptr) { folly_event_set( &event_, -1, EV_TIMEOUT, &AsyncTimeout::libeventCallback, this); event_.ev_base = nullptr; - RequestContext::saveContext(); } AsyncTimeout::~AsyncTimeout() { diff --git a/folly/io/async/EventBase.cpp b/folly/io/async/EventBase.cpp index b0e1eda6..340b2100 100644 --- a/folly/io/async/EventBase.cpp +++ b/folly/io/async/EventBase.cpp @@ -114,7 +114,6 @@ EventBase::EventBase(bool enableTimeMeasurement) } VLOG(5) << "EventBase(): Created."; initNotificationQueue(); - RequestContext::saveContext(); } // takes ownership of the event_base @@ -140,7 +139,6 @@ EventBase::EventBase(event_base* evb, bool enableTimeMeasurement) throw std::invalid_argument("EventBase(): event base cannot be nullptr"); } initNotificationQueue(); - RequestContext::saveContext(); } EventBase::~EventBase() { diff --git a/folly/io/async/NotificationQueue.h b/folly/io/async/NotificationQueue.h index e1b1cb36..fa66baea 100644 --- a/folly/io/async/NotificationQueue.h +++ b/folly/io/async/NotificationQueue.h @@ -266,8 +266,6 @@ class NotificationQueue { pid_(pid_t(getpid())), queue_() { - RequestContext::saveContext(); - #ifdef FOLLY_HAVE_EVENTFD if (fdType == FdType::EVENTFD) { eventfd_ = eventfd(0, EFD_CLOEXEC | EFD_NONBLOCK);