Reverted commit D3156698
authorMirek Klimos <miro@fb.com>
Wed, 20 Apr 2016 20:08:48 +0000 (13:08 -0700)
committerFacebook Github Bot 5 <facebook-github-bot-5-bot@fb.com>
Wed, 20 Apr 2016 20:20:40 +0000 (13:20 -0700)
Summary:There're currently two ways to set RequestContext
- RequestContext::create() - creates new context and sets it
- RequestContext::setContext(context) - sets context previously captured by saveContext
In most cases, the RequestContext is set back after the request is processed but sometimes it's not (especially with RequestContext::create). We want to measure cpu time for a request by measuring the total cpu time when a RequestContext is set, so we need to make sure that it's properly reset after the thread is done with the request. Scope guards can help us with that.

Reviewed By: haijunz

Differential Revision: D3156698

fb-gh-sync-id: 7c3eb06c1cc27849071625011bf64c5ad36c0612
fbshipit-source-id: 7c3eb06c1cc27849071625011bf64c5ad36c0612

folly/io/async/Request.h

index 5c1b969986f8e98cf66f5652a08d63d118f6b5f4..112f0fa8258f903d0ae1460a2ba83713a33c080c 100644 (file)
@@ -111,15 +111,12 @@ class RequestContext {
   }
 
   // The following API is used to pass the context through queues / threads.
-  // saveContext is called to get a shared_ptr to the context, and
+  // saveContext is called to geta shared_ptr to the context, and
   // setContext is used to reset it on the other side of the queue.
   //
-  // Whenever possible, use RequestContextScopeGuard instead of setContext
-  // to make sure that RequestContext is reset to the original value when
-  // we exit the scope.
-  //
   // A shared_ptr is used, because many request may fan out across
   // multiple threads, or do post-send processing, etc.
+
   static std::shared_ptr<RequestContext>
   setContext(std::shared_ptr<RequestContext> ctx) {
     using std::swap;
@@ -138,24 +135,4 @@ class RequestContext {
   std::map<std::string, std::unique_ptr<RequestData>> data_;
 };
 
-class RequestContextScopeGuard {
- private:
-  std::shared_ptr<RequestContext> prev_;
-
- public:
-  // Create a new RequestContext and reset to the original value when
-  // this goes out of scope.
-  RequestContextScopeGuard() : prev_(RequestContext::saveContext()) {
-    RequestContext::create();
-  }
-
-  // Set a RequestContext that was previously captured by saveContext(). It will
-  // be automatically reset to the original value when this goes out of scope.
-  explicit RequestContextScopeGuard(std::shared_ptr<RequestContext> ctx)
-      : prev_(RequestContext::setContext(std::move(ctx))) {}
-
-  ~RequestContextScopeGuard() {
-    RequestContext::setContext(std::move(prev_));
-  }
-};
 }