Commit 585616f7 authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Viswanath Sivakumar

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
parent f697ba49
...@@ -416,12 +416,29 @@ inline void FiberManager::initLocalData(Fiber& fiber) { ...@@ -416,12 +416,29 @@ inline void FiberManager::initLocalData(Fiber& fiber) {
} }
template <typename LocalT> template <typename LocalT>
FiberManager FiberManager::create( FiberManager::FiberManager(
std::unique_ptr<LoopController> loopController, LocalType<LocalT>,
Options options) { std::unique_ptr<LoopController> loopController__,
FiberManager fm(std::move(loopController), std::move(options)); Options options) :
fm.localType_ = typeid(LocalT); loopController_(std::move(loopController__)),
return fm; 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> template <typename F>
......
...@@ -32,26 +32,9 @@ __thread FiberManager* FiberManager::currentFiberManager_ = nullptr; ...@@ -32,26 +32,9 @@ __thread FiberManager* FiberManager::currentFiberManager_ = nullptr;
FiberManager::FiberManager(std::unique_ptr<LoopController> loopController, FiberManager::FiberManager(std::unique_ptr<LoopController> loopController,
Options options) : Options options) :
loopController_(std::move(loopController)), FiberManager(LocalType<void>(),
options_(options), std::move(loopController),
exceptionCallback_([](std::exception_ptr e, std::string context) { std::move(options)) {}
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::~FiberManager() { FiberManager::~FiberManager() {
if (isLoopScheduled_) { if (isLoopScheduled_) {
......
...@@ -43,6 +43,10 @@ class Fiber; ...@@ -43,6 +43,10 @@ class Fiber;
class LoopController; class LoopController;
class TimeoutController; class TimeoutController;
template <typename T>
class LocalType {
};
/** /**
* @class FiberManager * @class FiberManager
* @brief Single-threaded task execution engine. * @brief Single-threaded task execution engine.
...@@ -95,8 +99,6 @@ class FiberManager { ...@@ -95,8 +99,6 @@ class FiberManager {
FiberManager(const FiberManager&) = delete; FiberManager(const FiberManager&) = delete;
FiberManager& operator=(const FiberManager&) = delete; FiberManager& operator=(const FiberManager&) = delete;
FiberManager(FiberManager&&) = default;
FiberManager& operator=(FiberManager&&) = default;
/** /**
* Initializes, but doesn't start FiberManager loop * Initializes, but doesn't start FiberManager loop
...@@ -116,8 +118,9 @@ class FiberManager { ...@@ -116,8 +118,9 @@ class FiberManager {
* Locals of other types will be considered thread-locals. * Locals of other types will be considered thread-locals.
*/ */
template <typename LocalT> template <typename LocalT>
static FiberManager create(std::unique_ptr<LoopController> loopController, FiberManager(LocalType<LocalT>,
Options options = Options()); std::unique_ptr<LoopController> loopController,
Options options = Options());
~FiberManager(); ~FiberManager();
......
...@@ -1217,8 +1217,8 @@ TEST(FiberManager, remoteHasReadyTasks) { ...@@ -1217,8 +1217,8 @@ TEST(FiberManager, remoteHasReadyTasks) {
template <typename Data> template <typename Data>
void testFiberLocal() { void testFiberLocal() {
auto fm = FiberManager fm(LocalType<Data>(),
FiberManager::create<Data>(folly::make_unique<SimpleLoopController>()); folly::make_unique<SimpleLoopController>());
fm.addTask([]() { fm.addTask([]() {
EXPECT_EQ(42, local<Data>().value); EXPECT_EQ(42, local<Data>().value);
......
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