From bb5ed8070d533c016e1e93cd274e76ce28a780bb Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Sat, 20 Feb 2016 01:08:28 -0800 Subject: [PATCH] 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 --- folly/Makefile.am | 1 + folly/io/async/Request.cpp | 34 ++++++++++++++++++++++++++++++++++ folly/io/async/Request.h | 7 +------ 3 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 folly/io/async/Request.cpp diff --git a/folly/Makefile.am b/folly/Makefile.am index c70b9d2a..586dcc5a 100644 --- a/folly/Makefile.am +++ b/folly/Makefile.am @@ -380,6 +380,7 @@ libfolly_la_SOURCES = \ io/async/EventBaseLocal.cpp \ io/async/EventBaseManager.cpp \ io/async/EventHandler.cpp \ + io/async/Request.cpp \ io/async/SSLContext.cpp \ io/async/ScopedEventBaseThread.cpp \ io/async/HHWheelTimer.cpp \ diff --git a/folly/io/async/Request.cpp b/folly/io/async/Request.cpp new file mode 100644 index 00000000..7a048a35 --- /dev/null +++ b/folly/io/async/Request.cpp @@ -0,0 +1,34 @@ +/* + * 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 + +namespace folly { + +namespace { + +using SingletonT = SingletonThreadLocal>; +SingletonT singleton; +} + +std::shared_ptr& RequestContext::getStaticContext() { + return singleton.get(); +} +} diff --git a/folly/io/async/Request.h b/folly/io/async/Request.h index 8717503a..112f0fa8 100644 --- a/folly/io/async/Request.h +++ b/folly/io/async/Request.h @@ -23,7 +23,6 @@ #include #include #include -#include #include #include @@ -130,11 +129,7 @@ class RequestContext { } private: - static std::shared_ptr& getStaticContext() { - using SingletonT = SingletonThreadLocal>; - static SingletonT singleton; - return singleton.get(); - } + static std::shared_ptr& getStaticContext(); folly::RWSpinLock lock; std::map> data_; -- 2.34.1