Remove FiberManager move-constructor
authorAndrii Grynenko <andrii@fb.com>
Tue, 7 Apr 2015 18:19:46 +0000 (11:19 -0700)
committerViswanath Sivakumar <viswanath@fb.com>
Fri, 10 Apr 2015 03:34:29 +0000 (20:34 -0700)
Summary:
LoopController and Fibers keep references to FiberManager, so implementing move-constructor for it is non-trivial.
The only purpose of move constructor was to have a create() static method, replaced it with a constructor accepting a type tag.

Test Plan: unit test + tao build

Reviewed By: stepan@fb.com, pavlo@fb.com

Subscribers: folly-diffs@, yfeldblum, chalfant

FB internal diff: D1971881

Signature: t1:1971881:1428374073:945d913e69eaa6f957dace981c23835105d91935

folly/experimental/fibers/FiberManager-inl.h
folly/experimental/fibers/FiberManager.cpp
folly/experimental/fibers/FiberManager.h
folly/experimental/fibers/test/FibersTest.cpp

index 554d7c2802e55366f32d24dc835dc31ba8f0e5f6..45ca472a01bda04cd7c01d0bb7e1e0d481c23312 100644 (file)
@@ -416,12 +416,29 @@ inline void FiberManager::initLocalData(Fiber& fiber) {
 }
 
 template <typename LocalT>
-FiberManager FiberManager::create(
-    std::unique_ptr<LoopController> loopController,
-    Options options) {
-  FiberManager fm(std::move(loopController), std::move(options));
-  fm.localType_ = typeid(LocalT);
-  return fm;
+FiberManager::FiberManager(
+  LocalType<LocalT>,
+  std::unique_ptr<LoopController> loopController__,
+  Options options)  :
+    loopController_(std::move(loopController__)),
+    options_(std::move(options)),
+    exceptionCallback_([](std::exception_ptr eptr, std::string context) {
+        try {
+          std::rethrow_exception(eptr);
+        } catch (const std::exception& e) {
+          LOG(DFATAL) << "Exception " << typeid(e).name()
+                      << " with message '" << e.what() << "' was thrown in "
+                      << "FiberManager with context '" << context << "'";
+          throw;
+        } catch (...) {
+          LOG(DFATAL) << "Unknown exception was thrown in FiberManager with "
+                      << "context '" << context << "'";
+          throw;
+        }
+      }),
+    timeoutManager_(std::make_shared<TimeoutController>(*loopController_)),
+    localType_(typeid(LocalT)) {
+  loopController_->setFiberManager(this);
 }
 
 template <typename F>
index 5fb6bb9573ab5be1a4bd90f8d6a503fc84486cdc..744478ab981ab955850cce31f7d0ac9455d7c53d 100644 (file)
@@ -32,26 +32,9 @@ __thread FiberManager* FiberManager::currentFiberManager_ = nullptr;
 
 FiberManager::FiberManager(std::unique_ptr<LoopController> loopController,
                            Options options) :
-    loopController_(std::move(loopController)),
-    options_(options),
-    exceptionCallback_([](std::exception_ptr e, std::string context) {
-        try {
-          std::rethrow_exception(e);
-        } catch (const std::exception& e) {
-          LOG(DFATAL) << "Exception " << typeid(e).name()
-                      << " with message '" << e.what() << "' was thrown in "
-                      << "FiberManager with context '" << context << "'";
-          throw;
-        } catch (...) {
-          LOG(DFATAL) << "Unknown exception was thrown in FiberManager with "
-                      << "context '" << context << "'";
-          throw;
-        }
-      }),
-    timeoutManager_(std::make_shared<TimeoutController>(*loopController_)),
-    localType_(typeid(void)) {
-  loopController_->setFiberManager(this);
-}
+    FiberManager(LocalType<void>(),
+                 std::move(loopController),
+                 std::move(options)) {}
 
 FiberManager::~FiberManager() {
   if (isLoopScheduled_) {
index 49ccfa4a4acbc35680e3c1d882fd5457df9c8c36..ee55cd6d57e33d6d1fe07c9b1f4e47069243615f 100644 (file)
@@ -43,6 +43,10 @@ class Fiber;
 class LoopController;
 class TimeoutController;
 
+template <typename T>
+class LocalType {
+};
+
 /**
  * @class FiberManager
  * @brief Single-threaded task execution engine.
@@ -95,8 +99,6 @@ class FiberManager {
 
   FiberManager(const FiberManager&) = delete;
   FiberManager& operator=(const FiberManager&) = delete;
-  FiberManager(FiberManager&&) = default;
-  FiberManager& operator=(FiberManager&&) = default;
 
   /**
    * Initializes, but doesn't start FiberManager loop
@@ -116,8 +118,9 @@ class FiberManager {
    *                Locals of other types will be considered thread-locals.
    */
   template <typename LocalT>
-  static FiberManager create(std::unique_ptr<LoopController> loopController,
-                             Options options = Options());
+  FiberManager(LocalType<LocalT>,
+               std::unique_ptr<LoopController> loopController,
+               Options options = Options());
 
 
   ~FiberManager();
index 2aea08ab722ba28c2d677d7f0959aff26536c6c9..681e608f96defde30dd3837bd4bf1806c7149c28 100644 (file)
@@ -1217,8 +1217,8 @@ TEST(FiberManager, remoteHasReadyTasks) {
 
 template <typename Data>
 void testFiberLocal() {
-  auto fm =
-    FiberManager::create<Data>(folly::make_unique<SimpleLoopController>());
+  FiberManager fm(LocalType<Data>(),
+                  folly::make_unique<SimpleLoopController>());
 
   fm.addTask([]() {
       EXPECT_EQ(42, local<Data>().value);