From f2dd6e907017784bf048de44b4fd7afce926db23 Mon Sep 17 00:00:00 2001 From: Edmond <1571649+edmonddantes@users.noreply.github.com> Date: Sat, 4 Jul 2026 13:30:25 +0000 Subject: [PATCH] =?UTF-8?q?refactor(thread=5Fpool):=20drop=20now-redundant?= =?UTF-8?q?=20volatile=20locals=20=E2=80=94=20splitting=20the=20nested=20z?= =?UTF-8?q?end=5Ftry=20into=20helpers=20already=20clears=20-Wmaybe-uniniti?= =?UTF-8?q?alized;=20trim=20comments=20(true-async/server#93)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- thread_pool.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/thread_pool.c b/thread_pool.c index e36fe31..03e47c9 100644 --- a/thread_pool.c +++ b/thread_pool.c @@ -164,9 +164,7 @@ typedef struct { async_thread_channel_t *channel; } thread_pool_worker_ctx_t; -/* Call fcall under a bailout guard; returns true on bailout. Kept out of the - * worker handler so its outer zend_try does not nest another (GCC -O2 misfires - * -Wmaybe-uninitialized on the zend_try macro across nested setjmp). */ +/* Own function so the handler's zend_try isn't nested (GCC -Wmaybe-uninitialized). */ static bool thread_pool_call_guarded(zend_fcall_info *fci, zend_fcall_info_cache *fcc) { volatile bool bailed = false; @@ -178,8 +176,6 @@ static bool thread_pool_call_guarded(zend_fcall_info *fci, zend_fcall_info_cache return bailed; } -/* SUSPEND under a bailout guard; returns true on bailout. Same reason as - * thread_pool_call_guarded — keeps this zend_try out of the handler's. */ static bool thread_pool_suspend_guarded(void) { volatile bool bailed = false; @@ -327,8 +323,7 @@ static void thread_pool_worker_handler(zend_async_thread_event_t *event, void *c const zend_long kind = Z_LVAL_P(zend_hash_index_find(Z_ARRVAL(task), TASK_SLOT_KIND)); - /* volatile: these live across the loop's zend_try longjmp (C 7.13.2.1). */ - zend_future_shared_state_t * volatile state = + zend_future_shared_state_t *state = (zend_future_shared_state_t *)(uintptr_t) Z_LVAL_P( zend_hash_index_find(Z_ARRVAL(task), TASK_SLOT_STATE)); @@ -370,7 +365,7 @@ static void thread_pool_worker_handler(zend_async_thread_event_t *event, void *c } /* TASK_KIND_CLOSURE — original PHP-closure path. */ - async_thread_snapshot_t * volatile snapshot = + async_thread_snapshot_t *snapshot = (async_thread_snapshot_t *)(uintptr_t) Z_LVAL_P( zend_hash_index_find(Z_ARRVAL(task), TASK_SLOT_PAYLOAD_A)); const zval *args_zv = @@ -483,8 +478,8 @@ static void thread_pool_worker_handler(zend_async_thread_event_t *event, void *c /* Sync mode: run the body as a coroutine in a per-task nursery scope so * Async\spawn() inside it lands there. Cancel + drain before freeing the * snapshot so an un-awaited child can't outlive its arena. */ - zend_coroutine_t * volatile worker_coro = ZEND_ASYNC_CURRENT_COROUTINE; - zend_async_scope_t * volatile task_scope = + zend_coroutine_t *worker_coro = ZEND_ASYNC_CURRENT_COROUTINE; + zend_async_scope_t *task_scope = worker_coro != NULL ? ZEND_ASYNC_NEW_SCOPE(ZEND_ASYNC_CURRENT_SCOPE) : NULL; if (UNEXPECTED(task_scope == NULL)) { @@ -529,7 +524,7 @@ static void thread_pool_worker_handler(zend_async_thread_event_t *event, void *c /* Await the body; its callback copies result/error into our waker. A * fatal re-raises zend_bailout() out of the coroutine — caught here. */ - volatile bool body_bailed = false; + bool body_bailed = false; ZEND_ASYNC_WAKER_NEW(worker_coro); zend_async_resume_when(worker_coro, &body->event, false, zend_async_waker_callback_resolve, NULL);