You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
coro async-stack: make AsyncStackFrame and AsyncStackRoot immobile
Summary:
Make `AsyncStackFrame` and `AsyncStackRoot` immobile by explicitly deleting
copy/move constructors and assignment operators. These structures are
pointed-to by other parts of the async stack infrastructure, so moving them
after they are set up would invalidate pointers and corrupt the async stack
trace.
Changes:
- **AsyncStackFrame**: Delete copy/move ctor/assign, add `clear()` member
function that resets all members to their default state (as an alternative
to re-assignment).
- **AsyncStackRoot**: Delete copy/move ctor/assign, add explicit default
constructor. (AsyncStackRoot was already implicitly non-copyable/non-movable
due to its `std::atomic` member, but making it explicit is better practice.)
- **AsyncStack.cpp**: Refactor `makeDetachedRootFrame()` which returned
`AsyncStackFrame` by value. Now uses a static variable with a lambda-based
initializer to avoid requiring move semantics.
- **AsyncGenerator.h**: The `CleanupAwaitable` class previously embedded an
`AsyncStackFrame` as a direct member, but needed to be movable for the
`co_withAsyncStack` customization point. Introduced a nested `Awaiter` class
returned by `CleanupAwaitable::operator co_await()` that holds the
`AsyncStackFrame` as a direct member. This avoids heap allocation (no
`unique_ptr`/`make_unique`) while keeping `CleanupAwaitable` itself movable,
since the immobile `AsyncStackFrame` now lives in the awaiter which is
materialized directly in the coroutine frame via guaranteed copy elision.
Also replaced `asyncFrame_ = {}` in `clearContext()` with
`asyncFrame_.clear()`.
All changes applied to both `fbcode/folly/` and `xplat/folly/` copies.
Reviewed By: iahs
Differential Revision: D95416569
fbshipit-source-id: 9c78fdf04c688193ec9db2c94acb081546f75d01
0 commit comments