Skip to content

Commit 3e113d4

Browse files
committed
php#66: Add ZEND_ASYNC_SCHEDULER_LAUNCH() to TrueAsync public API
Expose async_scheduler_launch() function through the TrueAsync API to allow extensions to explicitly initialize and start the scheduler before creating coroutines. This is particularly useful for extensions that need deterministic scheduler initialization timing. Changes: - Add zend_async_scheduler_launch_t function pointer type - Add ZEND_ASYNC_SCHEDULER_LAUNCH() macro for scheduler initialization - Register scheduler_launch_fn as first parameter in zend_async_scheduler_register() - Update CHANGELOG.md with API addition in version 0.5.0
1 parent 3613ebd commit 3e113d4

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

Zend/zend_async_API.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ zend_async_new_future_t zend_async_new_future_fn = new_future_stub;
151151
zend_async_new_channel_t zend_async_new_channel_fn = new_channel_stub;
152152
zend_async_new_future_obj_t zend_async_new_future_obj_fn = new_future_obj_stub;
153153
zend_async_new_channel_obj_t zend_async_new_channel_obj_fn = new_channel_obj_stub;
154+
zend_async_scheduler_launch_t zend_async_scheduler_launch_fn = bool_stub;
154155

155156
/* GROUP API */
156157
zend_async_new_group_t zend_async_new_group_fn = new_group_stub;
@@ -261,6 +262,7 @@ ZEND_API int zend_async_get_api_version_number(void)
261262
}
262263

263264
ZEND_API bool zend_async_scheduler_register(char *module, bool allow_override,
265+
zend_async_scheduler_launch_t scheduler_launch_fn,
264266
zend_async_new_coroutine_t new_coroutine_fn, zend_async_new_scope_t new_scope_fn,
265267
zend_async_new_context_t new_context_fn, zend_async_spawn_t spawn_fn,
266268
zend_async_suspend_t suspend_fn, zend_async_enqueue_coroutine_t enqueue_coroutine_fn,
@@ -293,6 +295,7 @@ ZEND_API bool zend_async_scheduler_register(char *module, bool allow_override,
293295

294296
scheduler_module_name = module;
295297

298+
zend_async_scheduler_launch_fn = scheduler_launch_fn;
296299
zend_async_new_coroutine_fn = new_coroutine_fn;
297300
zend_async_new_scope_fn = new_scope_fn;
298301
zend_async_new_context_fn = new_context_fn;

Zend/zend_async_API.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include "zend_fibers.h"
2020
#include "zend_globals.h"
2121

22-
#define ZEND_ASYNC_API "TrueAsync API v0.6.0"
22+
#define ZEND_ASYNC_API "TrueAsync API v0.7.0"
2323
#define ZEND_ASYNC_API_VERSION_MAJOR 0
24-
#define ZEND_ASYNC_API_VERSION_MINOR 6
24+
#define ZEND_ASYNC_API_VERSION_MINOR 7
2525
#define ZEND_ASYNC_API_VERSION_PATCH 0
2626

2727
#define ZEND_ASYNC_API_VERSION_NUMBER \
@@ -250,6 +250,8 @@ typedef zend_async_group_t *(*zend_async_new_group_t)(size_t extra_size);
250250
typedef zend_object *(*zend_async_new_future_obj_t)(zend_future_t *future);
251251
typedef zend_object *(*zend_async_new_channel_obj_t)(zend_async_channel_t *channel);
252252

253+
typedef bool (*zend_async_scheduler_launch_t)(void);
254+
253255
typedef bool (*zend_async_reactor_startup_t)(void);
254256
typedef bool (*zend_async_reactor_shutdown_t)(void);
255257
typedef bool (*zend_async_reactor_execute_t)(bool no_wait);
@@ -1347,6 +1349,7 @@ ZEND_API extern zend_async_new_future_t zend_async_new_future_fn;
13471349
ZEND_API extern zend_async_new_channel_t zend_async_new_channel_fn;
13481350
ZEND_API extern zend_async_new_future_obj_t zend_async_new_future_obj_fn;
13491351
ZEND_API extern zend_async_new_channel_obj_t zend_async_new_channel_obj_fn;
1352+
ZEND_API extern zend_async_scheduler_launch_t zend_async_scheduler_launch_fn;
13501353

13511354
/* GROUP API */
13521355
ZEND_API extern zend_async_new_group_t zend_async_new_group_fn;
@@ -1409,6 +1412,7 @@ ZEND_API extern zend_async_queue_task_t zend_async_queue_task_fn;
14091412
ZEND_API extern zend_async_new_trigger_event_t zend_async_new_trigger_event_fn;
14101413

14111414
ZEND_API bool zend_async_scheduler_register(char *module, bool allow_override,
1415+
zend_async_scheduler_launch_t scheduler_launch_fn,
14121416
zend_async_new_coroutine_t new_coroutine_fn, zend_async_new_scope_t new_scope_fn,
14131417
zend_async_new_context_t new_context_fn, zend_async_spawn_t spawn_fn,
14141418
zend_async_suspend_t suspend_fn, zend_async_enqueue_coroutine_t enqueue_coroutine_fn,
@@ -1596,6 +1600,8 @@ END_EXTERN_C()
15961600
#define ZEND_ASYNC_GET_CE(type) zend_async_get_class_ce_fn(type)
15971601
#define ZEND_ASYNC_GET_EXCEPTION_CE(type) zend_async_get_class_ce_fn(type)
15981602

1603+
#define ZEND_ASYNC_SCHEDULER_LAUNCH() zend_async_scheduler_launch_fn()
1604+
15991605
#define ZEND_ASYNC_REACTOR_IS_ENABLED() zend_async_reactor_is_enabled()
16001606
#define ZEND_ASYNC_REACTOR_STARTUP() zend_async_reactor_startup_fn()
16011607
#define ZEND_ASYNC_REACTOR_SHUTDOWN() zend_async_reactor_shutdown_fn()

0 commit comments

Comments
 (0)