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
}
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>
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_) {
class LoopController;
class TimeoutController;
+template <typename T>
+class LocalType {
+};
+
/**
* @class FiberManager
* @brief Single-threaded task execution engine.
FiberManager(const FiberManager&) = delete;
FiberManager& operator=(const FiberManager&) = delete;
- FiberManager(FiberManager&&) = default;
- FiberManager& operator=(FiberManager&&) = default;
/**
* Initializes, but doesn't start FiberManager loop
* 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();
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);