Skip to content

Commit c23bd8b

Browse files
committed
Merge branch 'true-async-api' into true-async
2 parents 056cb6d + e1e7d6c commit c23bd8b

File tree

2 files changed

+80
-2
lines changed

2 files changed

+80
-2
lines changed

Zend/zend_async_API.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,18 @@ static void shutdown_stub(void) {}
4848

4949
static zend_array* get_coroutines_stub(void) { return NULL; }
5050

51+
static zend_future_t* future_create_stub(bool thread_safe, size_t extra_size)
52+
{
53+
ASYNC_THROW_ERROR("Async API is not enabled");
54+
return NULL;
55+
}
56+
57+
static zend_async_channel_t* channel_create_stub(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size)
58+
{
59+
ASYNC_THROW_ERROR("Async API is not enabled");
60+
return NULL;
61+
}
62+
5163
static void add_microtask_stub(zend_async_microtask_t *microtask) {}
5264

5365
static zend_array* get_awaiting_info_stub(zend_coroutine_t *coroutine) { return NULL; }
@@ -97,6 +109,8 @@ zend_async_get_coroutines_t zend_async_get_coroutines_fn = get_coroutines_stub;
97109
zend_async_add_microtask_t zend_async_add_microtask_fn = add_microtask_stub;
98110
zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn = get_awaiting_info_stub;
99111
zend_async_get_class_ce_t zend_async_get_class_ce_fn = get_class_ce;
112+
zend_async_future_create_t zend_async_future_create_fn = future_create_stub;
113+
zend_async_channel_create_t zend_async_channel_create_fn = channel_create_stub;
100114

101115
static zend_atomic_bool reactor_lock = {0};
102116
static char * reactor_module_name = NULL;

Zend/zend_async_API.h

Lines changed: 66 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.3.0"
22+
#define ZEND_ASYNC_API "TrueAsync API v0.4.0"
2323
#define ZEND_ASYNC_API_VERSION_MAJOR 0
24-
#define ZEND_ASYNC_API_VERSION_MINOR 3
24+
#define ZEND_ASYNC_API_VERSION_MINOR 4
2525
#define ZEND_ASYNC_API_VERSION_PATCH 0
2626

2727
#define ZEND_ASYNC_API_VERSION_NUMBER \
@@ -119,6 +119,16 @@ typedef enum
119119
* zend_coroutine_t is a Basic data structure that represents a coroutine in the Zend Engine.
120120
*/
121121
typedef struct _zend_coroutine_s zend_coroutine_t;
122+
123+
/**
124+
* zend_future_t is a data structure that represents a future result container.
125+
*/
126+
typedef struct _zend_future_s zend_future_t;
127+
128+
/**
129+
* zend_async_channel_t is a data structure that represents a communication channel.
130+
*/
131+
typedef struct _zend_async_channel_s zend_async_channel_t;
122132
typedef struct _zend_async_context_s zend_async_context_t;
123133
typedef struct _zend_async_waker_s zend_async_waker_t;
124134
typedef struct _zend_async_microtask_s zend_async_microtask_t;
@@ -127,6 +137,13 @@ typedef struct _zend_async_iterator_s zend_async_iterator_t;
127137
typedef struct _zend_fcall_s zend_fcall_t;
128138
typedef void (*zend_coroutine_entry_t)(void);
129139

140+
/* Future resolve function type */
141+
typedef void (*zend_future_resolve_t)(zend_future_t *future, zval *value, zend_object *exception, bool transfer_error);
142+
143+
/* Channel method function types */
144+
typedef bool (*zend_channel_send_t)(zend_async_channel_t *channel, zval *value);
145+
typedef bool (*zend_channel_receive_t)(zend_async_channel_t *channel, zval *result);
146+
130147
/* Coroutine Switch Handlers */
131148
typedef struct _zend_coroutine_switch_handler_s zend_coroutine_switch_handler_t;
132149
typedef struct _zend_coroutine_switch_handlers_vector_s zend_coroutine_switch_handlers_vector_t;
@@ -203,6 +220,8 @@ typedef zend_array* (*zend_async_get_coroutines_t)(void);
203220
typedef void (*zend_async_add_microtask_t)(zend_async_microtask_t *microtask);
204221
typedef zend_array* (*zend_async_get_awaiting_info_t)(zend_coroutine_t * coroutine);
205222
typedef zend_class_entry* (*zend_async_get_class_ce_t)(zend_async_class type);
223+
typedef zend_future_t* (*zend_async_future_create_t)(bool thread_safe, size_t extra_size);
224+
typedef zend_async_channel_t* (*zend_async_channel_create_t)(size_t buffer_size, bool resizable, bool thread_safe, size_t extra_size);
206225

207226
typedef void (*zend_async_reactor_startup_t)(void);
208227
typedef void (*zend_async_reactor_shutdown_t)(void);
@@ -963,6 +982,41 @@ struct _zend_coroutine_s {
963982
zend_coroutine_switch_handlers_vector_t *switch_handlers;
964983
};
965984

985+
/**
986+
* zend_future_t structure represents a future result container.
987+
* It inherits from zend_async_event_t to participate in the event system.
988+
*/
989+
struct _zend_future_s {
990+
zend_async_event_t event; /* Event inheritance (first member) */
991+
zval result; /* Result value (UNDEF = pending) */
992+
zend_object *exception; /* Exception object (NULL = no error) */
993+
994+
/* Debug information */
995+
zend_string *filename; /* Creation file */
996+
uint32_t lineno; /* Creation line */
997+
zend_string *resolved_filename; /* Resolution file */
998+
uint32_t resolved_lineno; /* Resolution line */
999+
1000+
/* Resolution method */
1001+
zend_future_resolve_t resolve;
1002+
};
1003+
1004+
/**
1005+
* zend_async_channel_t structure represents a communication channel.
1006+
* It inherits from zend_async_event_t to participate in the event system.
1007+
*/
1008+
struct _zend_async_channel_s {
1009+
zend_async_event_t event; /* Event inheritance (first member) */
1010+
1011+
/* Debug information */
1012+
zend_string *filename; /* Creation file */
1013+
uint32_t lineno; /* Creation line */
1014+
1015+
/* Channel-specific method pointers */
1016+
zend_channel_send_t send; /* Send method */
1017+
zend_channel_receive_t receive; /* Receive method */
1018+
};
1019+
9661020
/**
9671021
* The macro evaluates to TRUE if the coroutine is in a waiting state —
9681022
* either waiting for events or waiting in the execution queue.
@@ -1177,6 +1231,8 @@ ZEND_API extern zend_async_get_coroutines_t zend_async_get_coroutines_fn;
11771231
ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn;
11781232
ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn;
11791233
ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn;
1234+
ZEND_API extern zend_async_future_create_t zend_async_future_create_fn;
1235+
ZEND_API extern zend_async_channel_create_t zend_async_channel_create_fn;
11801236

11811237
/* Iterator API */
11821238
ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn;
@@ -1361,6 +1417,14 @@ ZEND_API void zend_async_add_main_coroutine_start_handler(
13611417

13621418
ZEND_API void zend_async_call_main_coroutine_start_handlers(zend_coroutine_t *main_coroutine);
13631419

1420+
/* Future API Functions */
1421+
#define ZEND_ASYNC_NEW_FUTURE(thread_safe) zend_async_future_create_fn(thread_safe, 0)
1422+
#define ZEND_ASYNC_NEW_FUTURE_EX(thread_safe, extra_size) zend_async_future_create_fn(thread_safe, extra_size)
1423+
1424+
/* Channel API Functions */
1425+
#define ZEND_ASYNC_NEW_CHANNEL(buffer_size, resizable, thread_safe) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, 0)
1426+
#define ZEND_ASYNC_NEW_CHANNEL_EX(buffer_size, resizable, thread_safe, extra_size) zend_async_channel_create_fn(buffer_size, resizable, thread_safe, extra_size)
1427+
13641428
END_EXTERN_C()
13651429

13661430
#define ZEND_ASYNC_IS_ENABLED() zend_async_is_enabled()

0 commit comments

Comments
 (0)