get rid of redundant calls to RequestContext::saveContext()
authorPingjia Shan <pingjia@fb.com>
Sun, 19 Nov 2017 05:55:44 +0000 (21:55 -0800)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Sun, 19 Nov 2017 06:20:54 +0000 (22:20 -0800)
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<std::shared_ptr<RequestContext>>`, 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<std::shared_ptr<RequestContext>>`, 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

folly/io/async/AsyncTimeout.cpp
folly/io/async/EventBase.cpp
folly/io/async/NotificationQueue.h

index f08b77719531cd01aabfc5c14374455eaa7656a4..680d64c1f4ced91fef96c14f78b3a6d23c42cbf9 100644 (file)
@@ -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() {
index b0e1eda68ae8332d4020d1282d852dcec1868ac1..340b2100d3d7a0826a3e43d6b95e63898422cbdd 100644 (file)
@@ -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() {
index e1b1cb36fe29b3ea4dd4149d28fd1d517b13d0bf..fa66baea7c9a80d1ddaa642496fe932143ea32ea 100644 (file)
@@ -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);