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) {
}
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>
......
......@@ -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_) {
......
......@@ -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();
......
......@@ -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);
......
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