@@ -238,9 +238,7 @@ typedef struct {
238238
239239/* Wrapped handler tables, one per original table (i.e. per coroutine
240240 * class). Process-lifetime: objects carrying a wrapper may outlive any
241- * request-local storage. Shared by every thread — mutate under the mutex
242- * (the same original table, std_object_handlers say, is hit from all of
243- * them). */
241+ * request-local storage. */
244242static HashTable * php_async_wrapped_handlers = NULL ;
245243static MUTEX_T php_async_wrapped_handlers_mutex = NULL ;
246244
@@ -324,9 +322,7 @@ static void php_async_coroutine_object_free(zend_object *object)
324322 wrapper -> original -> free_obj (object );
325323}
326324
327- /* get_gc for a wrapped coroutine object: the handle owns references (the
328- * bound entry, results, errors, the context) invisible to the class's own
329- * get_gc — a cycle through them would never collect. */
325+ /* The handle owns references the class's own get_gc cannot see. */
330326static HashTable * php_async_coroutine_object_gc (zend_object * object , zval * * table , int * num )
331327{
332328 const php_async_handlers_wrapper_t * wrapper =
@@ -345,9 +341,8 @@ static HashTable *php_async_coroutine_object_gc(zend_object *object, zval **tabl
345341 return ht ;
346342 }
347343
348- /* Original first, buffer second: if the original itself used the shared
349- * gc buffer, copying entry i over slot <= i is harmless, and the handle's
350- * entries only append after every original entry was read. */
344+ /* The original may have used this same shared buffer: create() resets it,
345+ * and copying entry i over slot <= i is safe. */
351346 zend_get_gc_buffer * buf = zend_get_gc_buffer_create ();
352347
353348 for (int i = 0 ; i < orig_num ; i ++ ) {
@@ -382,8 +377,7 @@ static HashTable *php_async_coroutine_object_gc(zend_object *object, zval **tabl
382377 }
383378 }
384379
385- /* The embedded internal-context table is not a collectable array itself —
386- * report its values, not the table. */
380+ /* Embedded, not a collectable array: report the values, not the table. */
387381 zval * zv ;
388382 ZEND_HASH_FOREACH_VAL (& handle -> coro .internal_context , zv ) {
389383 zend_get_gc_buffer_add_zval (buf , zv );
@@ -491,8 +485,7 @@ static void php_async_record_current(bool ok, zval *retval)
491485static zend_function php_async_root_function = { ZEND_INTERNAL_FUNCTION };
492486
493487/* Set by the switcher before a first entry: a fresh context has no other way
494- * to reach its handle. Thread-local: the write and the first-entry read must
495- * stay on the same thread. */
488+ * to reach its handle. */
496489ZEND_TLS php_coroutine_t * php_async_starting = NULL ;
497490
498491/* First-run trampoline: install a VM stack, run the body, return to the last
@@ -707,8 +700,7 @@ static ZEND_NAMED_FUNCTION(php_async_mandate_switch_to)
707700 RETURN_THROWS ();
708701 }
709702
710- /* The engine-level assert for this is a no-op in release builds, and a
711- * to == from switch corrupts the context machinery. */
703+ /* The engine only asserts to != from, and asserts are no-ops in release. */
712704 if (UNEXPECTED (handle -> ctx == EG (current_fiber_context ))) {
713705 zend_throw_error (NULL , "Cannot switch into the currently running coroutine" );
714706 RETURN_THROWS ();
0 commit comments