Commit 40e49acc authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Avoid mutex in RequestContext setShallowCopyContext

Summary:
Grabbing the mutex of the newly created context is unecessary cost.
folly::Synchronized's constructor support this optimization, so it's an easy change.

Reviewed By: yfeldblum

Differential Revision: D15600165

fbshipit-source-id: e92570a7ac7ac1e908d7c797bed6de22f940d387
parent 0f3478f4
......@@ -279,13 +279,8 @@ std::shared_ptr<RequestContext>& RequestContext::getStaticContext() {
/* static */ std::shared_ptr<RequestContext>
RequestContext::setShallowCopyContext() {
auto& parent = getStaticContext();
auto child = std::make_shared<RequestContext>();
if (parent) {
auto locks = folly::acquireLocked(as_const(parent->state_), child->state_);
*std::get<1>(locks) = *std::get<0>(locks);
}
auto child = parent ? std::make_shared<RequestContext>(*parent)
: std::make_shared<RequestContext>();
// Do not use setContext to avoid global set/unset
std::swap(child, parent);
return child;
......
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