19
19
#include "zend_fibers.h"
20
20
#include "zend_globals.h"
21
21
22
- #define ZEND_ASYNC_API "TrueAsync API v0.3 .0"
22
+ #define ZEND_ASYNC_API "TrueAsync API v0.4 .0"
23
23
#define ZEND_ASYNC_API_VERSION_MAJOR 0
24
- #define ZEND_ASYNC_API_VERSION_MINOR 3
24
+ #define ZEND_ASYNC_API_VERSION_MINOR 4
25
25
#define ZEND_ASYNC_API_VERSION_PATCH 0
26
26
27
27
#define ZEND_ASYNC_API_VERSION_NUMBER \
@@ -119,6 +119,16 @@ typedef enum
119
119
* zend_coroutine_t is a Basic data structure that represents a coroutine in the Zend Engine.
120
120
*/
121
121
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 ;
122
132
typedef struct _zend_async_context_s zend_async_context_t ;
123
133
typedef struct _zend_async_waker_s zend_async_waker_t ;
124
134
typedef struct _zend_async_microtask_s zend_async_microtask_t ;
@@ -127,6 +137,13 @@ typedef struct _zend_async_iterator_s zend_async_iterator_t;
127
137
typedef struct _zend_fcall_s zend_fcall_t ;
128
138
typedef void (* zend_coroutine_entry_t )(void );
129
139
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
+
130
147
/* Coroutine Switch Handlers */
131
148
typedef struct _zend_coroutine_switch_handler_s zend_coroutine_switch_handler_t ;
132
149
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);
203
220
typedef void (* zend_async_add_microtask_t )(zend_async_microtask_t * microtask );
204
221
typedef zend_array * (* zend_async_get_awaiting_info_t )(zend_coroutine_t * coroutine );
205
222
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 );
206
225
207
226
typedef void (* zend_async_reactor_startup_t )(void );
208
227
typedef void (* zend_async_reactor_shutdown_t )(void );
@@ -963,6 +982,41 @@ struct _zend_coroutine_s {
963
982
zend_coroutine_switch_handlers_vector_t * switch_handlers ;
964
983
};
965
984
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
+
966
1020
/**
967
1021
* The macro evaluates to TRUE if the coroutine is in a waiting state —
968
1022
* 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;
1177
1231
ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn ;
1178
1232
ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn ;
1179
1233
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 ;
1180
1236
1181
1237
/* Iterator API */
1182
1238
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(
1361
1417
1362
1418
ZEND_API void zend_async_call_main_coroutine_start_handlers (zend_coroutine_t * main_coroutine );
1363
1419
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
+
1364
1428
END_EXTERN_C ()
1365
1429
1366
1430
#define ZEND_ASYNC_IS_ENABLED () zend_async_is_enabled()
0 commit comments