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 ofFiberused to "helper" fields namedvalueandexceptioninzend_fiberto achieve this. This only works if you know that the resumed fiber is azend_fiberand 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_transferstruct has avaluefield that holds azvalfor both "normal" and error case (in case of an errorvaluehas 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 thecontextfield must be set to thezend_fiber_contextthat 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
INOUTparam to avoid unnecessary memory copies and have the caller decide where to allocate memory for it). Thecontextfield now refers to the fiber that has resumed us. Thevalueandflagsfields are also set by the other fiber. Ifvalueis not used it must be freed usingzval_ptr_dtor()to prevent memory leaks.