Unify control & data transfer between fibers #7120
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Provides a unified channel to transfer control and data using
zend_fiber_switch_context()
. This allows the caller ofzend_fiber_switch_context()
to pass along data that is needed by the resumed fiber. The implementation ofFiber
used to "helper" fields namedvalue
andexception
inzend_fiber
to achieve this. This only works if you know that the resumed fiber is azend_fiber
and it has different ways to pass values / errors. It also relies onEG(exception)
to be present in some situations. We should avoid that and ensure that all communication between fibers uses a single channel.The new
zend_fiber_transfer
struct has avalue
field that holds azval
for both "normal" and error case (in case of an errorvalue
has to be aThrowable
). No dynamic memory allocations are needed for transfers, they can always live on the caller's stack. A transfer struct has to be allocated before callingzend_fiber_switch_context()
and thecontext
field must be set to thezend_fiber_context
that should be resumed.After a fiber is resumed the transfer struct will hold context and data passed by the fiber that resumed us (the transfer is used as an
INOUT
param to avoid unnecessary memory copies and have the caller decide where to allocate memory for it). Thecontext
field now refers to the fiber that has resumed us. Thevalue
andflags
fields are also set by the other fiber. Ifvalue
is not used it must be freed usingzval_ptr_dtor()
to prevent memory leaks.