Commit aa669f8e authored by Lee Howes's avatar Lee Howes Committed by Facebook Github Bot

To reduce risk of stack overflow when catching up with deferred work, make...

To reduce risk of stack overflow when catching up with deferred work, make blocking operation runOnMainContext

Summary: Shift wait execution off of a (potential) fiber stack to reduce risk of stack overflows while running deferred work.

Reviewed By: andriigrynenko

Differential Revision: D16643654

fbshipit-source-id: 3ab1fe762b8f93c011cdb926e7689281018f54bc
parent 353be4c2
...@@ -572,11 +572,17 @@ class WaitExecutor final : public folly::Executor { ...@@ -572,11 +572,17 @@ class WaitExecutor final : public folly::Executor {
void drive() { void drive() {
baton_.wait(); baton_.wait();
baton_.reset(); #if FOLLY_FUTURE_USING_FIBER
auto funcs = std::move(queue_.wlock()->funcs); fibers::runInMainContext([&]() {
for (auto& func : funcs) { #endif
std::exchange(func, nullptr)(); baton_.reset();
} auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
#if FOLLY_FUTURE_USING_FIBER
});
#endif
} }
using Clock = std::chrono::steady_clock; using Clock = std::chrono::steady_clock;
...@@ -585,12 +591,18 @@ class WaitExecutor final : public folly::Executor { ...@@ -585,12 +591,18 @@ class WaitExecutor final : public folly::Executor {
if (!baton_.try_wait_until(deadline)) { if (!baton_.try_wait_until(deadline)) {
return false; return false;
} }
baton_.reset(); #if FOLLY_FUTURE_USING_FIBER
auto funcs = std::move(queue_.wlock()->funcs); return fibers::runInMainContext([&]() {
for (auto& func : funcs) { #endif
std::exchange(func, nullptr)(); baton_.reset();
} auto funcs = std::move(queue_.wlock()->funcs);
return true; for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
return true;
#if FOLLY_FUTURE_USING_FIBER
});
#endif
} }
void detach() { void detach() {
......
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