From: Mirek Klimos Date: Wed, 20 Apr 2016 20:08:48 +0000 (-0700) Subject: Reverted commit D3156698 X-Git-Tag: 2016.07.26~339 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bc9d9e8cfaceda506f7fe72dc0ce4b18d81dad2b;p=folly.git Reverted commit D3156698 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 --- diff --git a/folly/io/async/Request.h b/folly/io/async/Request.h index 5c1b9699..112f0fa8 100644 --- a/folly/io/async/Request.h +++ b/folly/io/async/Request.h @@ -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 setContext(std::shared_ptr ctx) { using std::swap; @@ -138,24 +135,4 @@ class RequestContext { std::map> data_; }; -class RequestContextScopeGuard { - private: - std::shared_ptr 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 ctx) - : prev_(RequestContext::setContext(std::move(ctx))) {} - - ~RequestContextScopeGuard() { - RequestContext::setContext(std::move(prev_)); - } -}; }