Skip to content

Commit 538dd73

Browse files
committed
zend_async_API: drop dead key_name lookup; trim comments
zend_async_internal_context_key_name had no callers anywhere in the tree. The key registry is written only at MINIT, so the read-side lock added earlier was unnecessary and is gone with the function.
1 parent 3f3e641 commit 538dd73

3 files changed

Lines changed: 7 additions & 32 deletions

File tree

Zend/zend_async_API.c

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -110,22 +110,6 @@ ZEND_API uint32_t zend_async_internal_context_key_alloc(const char *key_name)
110110
return key;
111111
}
112112

113-
ZEND_API const char *zend_async_internal_context_key_name(uint32_t key)
114-
{
115-
/* A non-NULL table implies the mutex exists: key_alloc creates the mutex
116-
* before the table. The lock shields the read from a concurrent alloc
117-
* rehashing the bucket array. */
118-
if (internal_context_key_names == NULL) {
119-
return NULL;
120-
}
121-
122-
tsrm_mutex_lock(internal_context_mutex);
123-
const char *name = zend_hash_index_find_ptr(internal_context_key_names, key);
124-
tsrm_mutex_unlock(internal_context_mutex);
125-
126-
return name;
127-
}
128-
129113
static void internal_context_keys_shutdown(void)
130114
{
131115
if (internal_context_key_names != NULL) {

Zend/zend_async_API.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,6 @@ ZEND_API const char *zend_async_get_scheduler_module(void);
476476
* one. Values may hold raw C data, so the store is structurally
477477
* unreachable from PHP. */
478478
ZEND_API uint32_t zend_async_internal_context_key_alloc(const char *key_name);
479-
ZEND_API const char *zend_async_internal_context_key_name(uint32_t key);
480479
ZEND_API zval *zend_async_internal_context_find(zend_coroutine_t *coroutine, uint32_t key);
481480
ZEND_API bool zend_async_internal_context_set(
482481
zend_coroutine_t *coroutine, uint32_t key, zval *value);

ext/async_scheduler_hook/async_scheduler_hook.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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. */
244242
static HashTable *php_async_wrapped_handlers = NULL;
245243
static 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. */
330326
static 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)
491485
static 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. */
496489
ZEND_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

Comments
 (0)