From 585616f77aaa2bbd7a8296f2df839f188e3408b8 Mon Sep 17 00:00:00 2001 From: Andrii Grynenko Date: Tue, 7 Apr 2015 11:19:46 -0700 Subject: [PATCH] Remove FiberManager move-constructor 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 | 29 +++++++++++++++---- folly/experimental/fibers/FiberManager.cpp | 23 ++------------- folly/experimental/fibers/FiberManager.h | 11 ++++--- folly/experimental/fibers/test/FibersTest.cpp | 4 +-- 4 files changed, 35 insertions(+), 32 deletions(-) diff --git a/folly/experimental/fibers/FiberManager-inl.h b/folly/experimental/fibers/FiberManager-inl.h index 554d7c28..45ca472a 100644 --- a/folly/experimental/fibers/FiberManager-inl.h +++ b/folly/experimental/fibers/FiberManager-inl.h @@ -416,12 +416,29 @@ inline void FiberManager::initLocalData(Fiber& fiber) { } template -FiberManager FiberManager::create( - std::unique_ptr loopController, - Options options) { - FiberManager fm(std::move(loopController), std::move(options)); - fm.localType_ = typeid(LocalT); - return fm; +FiberManager::FiberManager( + LocalType, + std::unique_ptr 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(*loopController_)), + localType_(typeid(LocalT)) { + loopController_->setFiberManager(this); } template diff --git a/folly/experimental/fibers/FiberManager.cpp b/folly/experimental/fibers/FiberManager.cpp index 5fb6bb95..744478ab 100644 --- a/folly/experimental/fibers/FiberManager.cpp +++ b/folly/experimental/fibers/FiberManager.cpp @@ -32,26 +32,9 @@ __thread FiberManager* FiberManager::currentFiberManager_ = nullptr; FiberManager::FiberManager(std::unique_ptr 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(*loopController_)), - localType_(typeid(void)) { - loopController_->setFiberManager(this); -} + FiberManager(LocalType(), + std::move(loopController), + std::move(options)) {} FiberManager::~FiberManager() { if (isLoopScheduled_) { diff --git a/folly/experimental/fibers/FiberManager.h b/folly/experimental/fibers/FiberManager.h index 49ccfa4a..ee55cd6d 100644 --- a/folly/experimental/fibers/FiberManager.h +++ b/folly/experimental/fibers/FiberManager.h @@ -43,6 +43,10 @@ class Fiber; class LoopController; class TimeoutController; +template +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 - static FiberManager create(std::unique_ptr loopController, - Options options = Options()); + FiberManager(LocalType, + std::unique_ptr loopController, + Options options = Options()); ~FiberManager(); diff --git a/folly/experimental/fibers/test/FibersTest.cpp b/folly/experimental/fibers/test/FibersTest.cpp index 2aea08ab..681e608f 100644 --- a/folly/experimental/fibers/test/FibersTest.cpp +++ b/folly/experimental/fibers/test/FibersTest.cpp @@ -1217,8 +1217,8 @@ TEST(FiberManager, remoteHasReadyTasks) { template void testFiberLocal() { - auto fm = - FiberManager::create(folly::make_unique()); + FiberManager fm(LocalType(), + folly::make_unique()); fm.addTask([]() { EXPECT_EQ(42, local().value); -- 2.34.1