Skip to content

Split fiber status and flags #7094

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 3, 2021
Merged

Split fiber status and flags #7094

merged 1 commit into from
Jun 3, 2021

Conversation

trowski
Copy link
Member

@trowski trowski commented Jun 3, 2021

This splits the fiber running status from flags about how the fiber exited: normally, with an exception, bailout, or forced destroyed.

Observers are better able to differentiate running status from exiting (e.g., a fiber is running because it is being destroyed vs. a fiber is dead and was destroyed), which is why the dubious output of ext/zend_test/tests/observer_fiber_05.phpt is now improved with this change.

Co-Authored-By: twosee <twose@qq.com>
@trowski trowski merged commit d2e5203 into php:master Jun 3, 2021
@@ -711,13 +712,15 @@ ZEND_METHOD(Fiber, getReturn)

fiber = (zend_fiber *) Z_OBJ_P(getThis());

if (fiber->status != ZEND_FIBER_STATUS_RETURNED) {
if (fiber->status != ZEND_FIBER_STATUS_DEAD || fiber->flags) {
Copy link
Member

@twose twose Jun 4, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can only get the return value after the fiber is dead, so the || fiber->flags here seem unnecessary, and it assumes that the flags are always used to indicate the error state, and we may add more other flags in the future.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A fiber can be dead but have not returned a value (i.e., threw an exception). If flags are used for something other than error conditions then we'll have to revisit this, but it's fine for now.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean

if (fiber->status == ZEND_FIBER_STATUS_INIT) {
    ...
} else if (fiber->status == ZEND_FIBER_STATUS_DEAD) {
   if (fiber->flags ...) { ... }
} else {
   ...
}

It looks like you're being lazy.

@trowski trowski deleted the fiber-flags branch June 4, 2021 04:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants