Move RequestContext::getStaticContext to .cpp
authorAndrii Grynenko <andrii@fb.com>
Sat, 20 Feb 2016 09:08:28 +0000 (01:08 -0800)
committerfacebook-github-bot-4 <folly-bot@fb.com>
Sat, 20 Feb 2016 09:20:26 +0000 (01:20 -0800)
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
folly/io/async/Request.cpp [new file with mode: 0644]
folly/io/async/Request.h

index c70b9d2a152a00e832dd8bcc102ced686ae3e31b..586dcc5a3960cc6317db5f5c0c6ee98c9e9cef46 100644 (file)
@@ -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 (file)
index 0000000..7a048a3
--- /dev/null
@@ -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 <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();
+}
+}
index 8717503a9209db9f90db536264a6367af6f8c9ab..112f0fa8258f903d0ae1460a2ba83713a33c080c 100644 (file)
@@ -23,7 +23,6 @@
 #include <map>
 #include <memory>
 #include <glog/logging.h>
-#include <folly/ThreadLocal.h>
 #include <folly/RWSpinLock.h>
 #include <folly/SingletonThreadLocal.h>
 
@@ -130,11 +129,7 @@ class RequestContext {
   }
 
  private:
-  static std::shared_ptr<RequestContext>& getStaticContext() {
-    using SingletonT = SingletonThreadLocal<std::shared_ptr<RequestContext>>;
-    static SingletonT singleton;
-    return singleton.get();
-  }
+  static std::shared_ptr<RequestContext>& getStaticContext();
 
   folly::RWSpinLock lock;
   std::map<std::string, std::unique_ptr<RequestData>> data_;