Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113183 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 43372 invoked from network); 15 Feb 2021 18:07:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 15 Feb 2021 18:07:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 47390180506 for ; Mon, 15 Feb 2021 09:54:13 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mercury.negativeion.net (mercury.negativeion.net [199.38.81.6]) by php-smtp4.php.net (Postfix) with ESMTP for ; Mon, 15 Feb 2021 09:54:12 -0800 (PST) Received: from localhost (localhost [127.0.0.1]) by mercury.negativeion.net (Postfix) with ESMTP id 3834220C6EC661; Mon, 15 Feb 2021 12:54:12 -0500 (EST) Received: from mercury.negativeion.net ([127.0.0.1]) by localhost (mercury.negativeion.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 649Oo81VpdwS; Mon, 15 Feb 2021 12:54:11 -0500 (EST) Received: from [10.0.1.101] (unknown [173.225.146.47]) by mercury.negativeion.net (Postfix) with ESMTPSA id 7C78C20C6EC651; Mon, 15 Feb 2021 12:54:11 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 13.4 \(3608.120.23.2.1\)) In-Reply-To: <458846A1-950A-404F-BD75-BD70F73D3625@trowski.com> Date: Mon, 15 Feb 2021 11:54:10 -0600 Cc: Benjamin Eberlei , php internals Content-Transfer-Encoding: quoted-printable Message-ID: References: <9BF046F2-4799-4CCD-A7F0-739A91C77E83@trowski.com> <458846A1-950A-404F-BD75-BD70F73D3625@trowski.com> To: Levi Morrison X-Mailer: Apple Mail (2.3608.120.23.2.1) Subject: Re: [PHP-DEV] [RFC] Fibers From: aaron@trowski.com (Aaron Piotrowski) > On Feb 3, 2021, at 11:32 AM, Aaron Piotrowski = wrote: >=20 >=20 >> On Jan 31, 2021, at 11:29 AM, Levi Morrison via internals = wrote: >>=20 >> 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. >>=20 >=20 > Hi Levi, >=20 > Yes, I agree and will look at implementing an observer API. >=20 > Cheers, > Aaron Piotrowski >=20 >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: 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=E2=80=99s something missing or improvements that = could be made. Cheers, Aaron Piotrowski=