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 {
void drive() {
baton_.wait();
baton_.reset();
auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
#if FOLLY_FUTURE_USING_FIBER
fibers::runInMainContext([&]() {
#endif
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;
......@@ -585,12 +591,18 @@ class WaitExecutor final : public folly::Executor {
if (!baton_.try_wait_until(deadline)) {
return false;
}
baton_.reset();
auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
return true;
#if FOLLY_FUTURE_USING_FIBER
return fibers::runInMainContext([&]() {
#endif
baton_.reset();
auto funcs = std::move(queue_.wlock()->funcs);
for (auto& func : funcs) {
std::exchange(func, nullptr)();
}
return true;
#if FOLLY_FUTURE_USING_FIBER
});
#endif
}
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