diff --git a/folly/futures/detail/Core.cpp b/folly/futures/detail/Core.cpp index 74ed6d913f7..2e8583742e3 100644 --- a/folly/futures/detail/Core.cpp +++ b/folly/futures/detail/Core.cpp @@ -42,20 +42,6 @@ void UniqueDeleter::operator()(DeferredExecutor* ptr) { } } -KeepAliveOrDeferred::KeepAliveOrDeferred() noexcept : state_(State::Deferred) { - ::new (&deferred_) DW{}; -} - -KeepAliveOrDeferred::KeepAliveOrDeferred(KA ka) noexcept - : state_(State::KeepAlive) { - ::new (&keepAlive_) KA{std::move(ka)}; -} - -KeepAliveOrDeferred::KeepAliveOrDeferred(DW deferred) noexcept - : state_(State::Deferred) { - ::new (&deferred_) DW{std::move(deferred)}; -} - KeepAliveOrDeferred::KeepAliveOrDeferred(KeepAliveOrDeferred&& other) noexcept : state_(other.state_) { switch (state_) { @@ -316,21 +302,6 @@ bool CoreBase::hasResult() const noexcept { return State() != (state & allowed); } -Executor* CoreBase::getExecutor() const { - if (!executor_.isKeepAlive()) { - return nullptr; - } - return executor_.getKeepAliveExecutor(); -} - -DeferredExecutor* CoreBase::getDeferredExecutor() const { - if (!executor_.isDeferred()) { - return {}; - } - - return executor_.getDeferredExecutor(); -} - DeferredWrapper CoreBase::stealDeferredExecutor() { if (executor_.isKeepAlive()) { return {}; @@ -436,9 +407,6 @@ class CoreBase::CoreAndCallbackReference { CoreBase* core_{nullptr}; }; -CoreBase::CoreBase(State state, unsigned char attached) - : state_(state), attached_(attached) {} - CoreBase::~CoreBase() { auto interrupt = interrupt_.load(std::memory_order_acquire); auto pointer = interrupt & ~InterruptMask; diff --git a/folly/futures/detail/Core.h b/folly/futures/detail/Core.h index 63f5971b6ee..2fb6c760bca 100644 --- a/folly/futures/detail/Core.h +++ b/folly/futures/detail/Core.h @@ -83,9 +83,18 @@ class KeepAliveOrDeferred { using DW = DeferredWrapper; public: - KeepAliveOrDeferred() noexcept; - /* implicit */ KeepAliveOrDeferred(KA ka) noexcept; - /* implicit */ KeepAliveOrDeferred(DW deferred) noexcept; + KeepAliveOrDeferred() noexcept : state_(State::Deferred), deferred_(DW{}) {} + + /* implicit */ KeepAliveOrDeferred(KA ka) noexcept + : state_(State::KeepAlive) { + ::new (&keepAlive_) KA{std::move(ka)}; + } + + /* implicit */ KeepAliveOrDeferred(DW deferred) noexcept + : state_(State::Deferred) { + ::new (&deferred_) DW{std::move(deferred)}; + } + KeepAliveOrDeferred(KeepAliveOrDeferred&& other) noexcept; ~KeepAliveOrDeferred(); @@ -474,7 +483,8 @@ class CoreBase { } protected: - CoreBase(State state, unsigned char attached); + CoreBase(State state, unsigned char attached) noexcept + : state_(state), attached_(attached) {} virtual ~CoreBase(); @@ -701,6 +711,21 @@ class Core final : private ResultHolder, public CoreBase { } }; +inline Executor* CoreBase::getExecutor() const { + if (!executor_.isKeepAlive()) { + return nullptr; + } + return executor_.getKeepAliveExecutor(); +} + +inline DeferredExecutor* CoreBase::getDeferredExecutor() const { + if (!executor_.isDeferred()) { + return {}; + } + + return executor_.getDeferredExecutor(); +} + #if FOLLY_USE_EXTERN_FUTURE_UNIT // limited to the instances unconditionally forced by the futures library extern template class Core;