Commit bb5ed807 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by facebook-github-bot-4

Move RequestContext::getStaticContext to .cpp

Summary: All singleton registration has to happen in .cpp. Otherwise singleton may be double registered if inlined.

Reviewed By: yfeldblum

Differential Revision: D2956951

fb-gh-sync-id: bea425c31270d614f4b8a780204694168602fe86
shipit-source-id: bea425c31270d614f4b8a780204694168602fe86
parent 743a0b48
...@@ -380,6 +380,7 @@ libfolly_la_SOURCES = \ ...@@ -380,6 +380,7 @@ libfolly_la_SOURCES = \
io/async/EventBaseLocal.cpp \ io/async/EventBaseLocal.cpp \
io/async/EventBaseManager.cpp \ io/async/EventBaseManager.cpp \
io/async/EventHandler.cpp \ io/async/EventHandler.cpp \
io/async/Request.cpp \
io/async/SSLContext.cpp \ io/async/SSLContext.cpp \
io/async/ScopedEventBaseThread.cpp \ io/async/ScopedEventBaseThread.cpp \
io/async/HHWheelTimer.cpp \ io/async/HHWheelTimer.cpp \
......
/*
* Copyright 2016 Facebook, Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include <folly/io/async/Request.h>
namespace folly {
namespace {
using SingletonT = SingletonThreadLocal<std::shared_ptr<RequestContext>>;
SingletonT singleton;
}
std::shared_ptr<RequestContext>& RequestContext::getStaticContext() {
return singleton.get();
}
}
...@@ -23,7 +23,6 @@ ...@@ -23,7 +23,6 @@
#include <map> #include <map>
#include <memory> #include <memory>
#include <glog/logging.h> #include <glog/logging.h>
#include <folly/ThreadLocal.h>
#include <folly/RWSpinLock.h> #include <folly/RWSpinLock.h>
#include <folly/SingletonThreadLocal.h> #include <folly/SingletonThreadLocal.h>
...@@ -130,11 +129,7 @@ class RequestContext { ...@@ -130,11 +129,7 @@ class RequestContext {
} }
private: private:
static std::shared_ptr<RequestContext>& getStaticContext() { static std::shared_ptr<RequestContext>& getStaticContext();
using SingletonT = SingletonThreadLocal<std::shared_ptr<RequestContext>>;
static SingletonT singleton;
return singleton.get();
}
folly::RWSpinLock lock; folly::RWSpinLock lock;
std::map<std::string, std::unique_ptr<RequestData>> data_; std::map<std::string, std::unique_ptr<RequestData>> data_;
......
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