Re: [RFC] Fibers

From: Date: Mon, 15 Feb 2021 17:54:10 +0000
Subject: Re: [RFC] Fibers
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-113183@lists.php.net to get a copy of this message
> On Feb 3, 2021, at 11:32 AM, Aaron Piotrowski <aaron@trowski.com> wrote: > > >> On Jan 31, 2021, at 11:29 AM, Levi Morrison via internals <internals@lists.php.net> >> wrote: >> >> I think it would probably be advantageous to have an observer that >> alerts interested parties when the fiber switches. This way we can >> avoid querying the current fiber on every fcall. >> > > Hi Levi, > > Yes, I agree and will look at implementing an observer API. > > Cheers, > Aaron Piotrowski > >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: https://www.php.net/unsub.php >> <https://www.php.net/unsub.php> Hi Levi, I implemented an observer that notifies registered handlers whenever the current fiber context is switched. typedef void (*zend_observer_fiber_switch_handler)(zend_fiber *from, zend_fiber *to); PHP_FIBER_API void zend_observer_fiber_switch_register(zend_observer_fiber_switch_handler handler); This works similar to the error observer API. zend_fiber provides access to a unique ID, zend_execute_data, etc. that should be sufficient for code profilers, debuggers, etc. One pointer is NULL if {main} is the from or to fiber. The handlers are invoked before switching to the fiber and after suspending from a fiber. Let me know if there’s something missing or improvements that could be made. Cheers, Aaron Piotrowski

« previous php.internals (#113183) next »