Commit cf7fad82 authored by Lewis Baker's avatar Lewis Baker Committed by Facebook GitHub Bot

Update AsyncScope so that the first frame's return-address is the .add() callsite

Summary:
Modify the AsyncScope::add() method so that it records the call-site of .add()
as the first frame's return address instead of recording .add() itself as the
first frame.

This should hopefully give a bit more insight into where the detached task was
launched.

Reviewed By: andriigrynenko

Differential Revision: D24478808

fbshipit-source-id: 0723891e77af5e52c7f8c13e218e4fb9120867e3
parent 2e9437e4
......@@ -149,12 +149,13 @@ inline std::size_t AsyncScope::remaining() const noexcept {
}
template <typename Awaitable>
inline void AsyncScope::add(Awaitable&& awaitable) {
FOLLY_NOINLINE inline void AsyncScope::add(Awaitable&& awaitable) {
assert(
!joined_ &&
"It is invalid to add() more work after work has been joined");
anyTasksStarted_.store(true, std::memory_order_relaxed);
addImpl((Awaitable &&) awaitable).start(&barrier_);
addImpl((Awaitable &&) awaitable)
.start(&barrier_, FOLLY_ASYNC_STACK_RETURN_ADDRESS());
}
inline Task<void> AsyncScope::joinAsync() noexcept {
......
......@@ -194,12 +194,16 @@ class DetachedBarrierTask {
}
FOLLY_NOINLINE void start(Barrier* barrier) && noexcept {
std::move(*this).start(barrier, FOLLY_ASYNC_STACK_RETURN_ADDRESS());
}
void start(Barrier* barrier, void* returnAddress) && noexcept {
assert(coro_);
assert(barrier != nullptr);
barrier->add(1);
auto coro = std::exchange(coro_, {});
coro.promise().setBarrier(barrier);
coro.promise().getAsyncFrame().setReturnAddress();
coro.promise().getAsyncFrame().setReturnAddress(returnAddress);
folly::resumeCoroutineWithNewAsyncStackRoot(coro);
}
......
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