Commit 47ef08c0 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook Github Bot

Move executor to local var immediately in doCallback

Summary:
[Folly] Move executor to local var immediately in `doCallback`, and always move it into the callback.

(Note: this ignores all push blocking failures!)

Reviewed By: andrewcox

Differential Revision: D15532854

fbshipit-source-id: 971a6a64ad3c47c9f5e9f75907a568f9d59b1000
parent 0236a802
...@@ -601,13 +601,13 @@ class Core final { ...@@ -601,13 +601,13 @@ class Core final {
void doCallback(Executor::KeepAlive<>&& completingKA, State priorState) { void doCallback(Executor::KeepAlive<>&& completingKA, State priorState) {
DCHECK(state_ == State::Done); DCHECK(state_ == State::Done);
auto executor = std::exchange(executor_, Executor::KeepAlive<>());
bool allowInline = bool allowInline =
(executor_.get() == completingKA.get() && (executor.get() == completingKA.get() &&
priorState == State::OnlyCallbackAllowInline); priorState == State::OnlyCallbackAllowInline);
// If we have no executor or if we are allowing inline executor on a // If we have no executor or if we are allowing inline executor on a
// matching executor, run inline. // matching executor, run inline.
if (executor_ && !allowInline) { if (executor && !allowInline) {
auto x = std::exchange(executor_, Executor::KeepAlive<>());
exception_wrapper ew; exception_wrapper ew;
// We need to reset `callback_` after it was executed (which can happen // We need to reset `callback_` after it was executed (which can happen
// through the executor or, if `Executor::add` throws, below). The // through the executor or, if `Executor::add` throws, below). The
...@@ -623,13 +623,13 @@ class Core final { ...@@ -623,13 +623,13 @@ class Core final {
CoreAndCallbackReference guard_local_scope(this); CoreAndCallbackReference guard_local_scope(this);
CoreAndCallbackReference guard_lambda(this); CoreAndCallbackReference guard_lambda(this);
try { try {
auto xPtr = x.get(); auto xPtr = executor.get();
xPtr->add([core_ref = std::move(guard_lambda), xPtr->add([core_ref = std::move(guard_lambda),
keepAlive = std::move(x)]() mutable { executor = std::move(executor)]() mutable {
auto cr = std::move(core_ref); auto cr = std::move(core_ref);
Core* const core = cr.getCore(); Core* const core = cr.getCore();
RequestContextScopeGuard rctx(std::move(core->context_)); RequestContextScopeGuard rctx(std::move(core->context_));
core->callback_(std::move(keepAlive), std::move(core->result_)); core->callback_(std::move(executor), std::move(core->result_));
}); });
} catch (const std::exception& e) { } catch (const std::exception& e) {
ew = exception_wrapper(std::current_exception(), e); ew = exception_wrapper(std::current_exception(), e);
...@@ -649,7 +649,7 @@ class Core final { ...@@ -649,7 +649,7 @@ class Core final {
detachOne(); detachOne();
}; };
RequestContextScopeGuard rctx(std::move(context_)); RequestContextScopeGuard rctx(std::move(context_));
callback_(executor_.copy(), std::move(result_)); callback_(std::move(executor), std::move(result_));
} }
} }
......
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