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 \
@@ -124,6 +124,11 @@ typedef struct _zend_coroutine_s zend_coroutine_t;
124
124
* zend_future_t is a data structure that represents a future result container.
125
125
*/
126
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 ;
127
132
typedef struct _zend_async_context_s zend_async_context_t ;
128
133
typedef struct _zend_async_waker_s zend_async_waker_t ;
129
134
typedef struct _zend_async_microtask_s zend_async_microtask_t ;
@@ -135,6 +140,10 @@ typedef void (*zend_coroutine_entry_t)(void);
135
140
/* Future resolve function type */
136
141
typedef void (* zend_future_resolve_t )(zend_future_t * future , zval * value , zend_object * exception , bool transfer_error );
137
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
+
138
147
/* Coroutine Switch Handlers */
139
148
typedef struct _zend_coroutine_switch_handler_s zend_coroutine_switch_handler_t ;
140
149
typedef struct _zend_coroutine_switch_handlers_vector_s zend_coroutine_switch_handlers_vector_t ;
@@ -212,6 +221,7 @@ typedef void (*zend_async_add_microtask_t)(zend_async_microtask_t *microtask);
212
221
typedef zend_array * (* zend_async_get_awaiting_info_t )(zend_coroutine_t * coroutine );
213
222
typedef zend_class_entry * (* zend_async_get_class_ce_t )(zend_async_class type );
214
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 );
215
225
216
226
typedef void (* zend_async_reactor_startup_t )(void );
217
227
typedef void (* zend_async_reactor_shutdown_t )(void );
@@ -991,6 +1001,22 @@ struct _zend_future_s {
991
1001
zend_future_resolve_t resolve ;
992
1002
};
993
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
+
994
1020
/**
995
1021
* The macro evaluates to TRUE if the coroutine is in a waiting state —
996
1022
* either waiting for events or waiting in the execution queue.
@@ -1206,6 +1232,7 @@ ZEND_API extern zend_async_add_microtask_t zend_async_add_microtask_fn;
1206
1232
ZEND_API extern zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn ;
1207
1233
ZEND_API extern zend_async_get_class_ce_t zend_async_get_class_ce_fn ;
1208
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 ;
1209
1236
1210
1237
/* Iterator API */
1211
1238
ZEND_API extern zend_async_new_iterator_t zend_async_new_iterator_fn ;
@@ -1394,6 +1421,10 @@ ZEND_API void zend_async_call_main_coroutine_start_handlers(zend_coroutine_t *ma
1394
1421
#define ZEND_ASYNC_NEW_FUTURE (thread_safe ) zend_async_future_create_fn(thread_safe, 0)
1395
1422
#define ZEND_ASYNC_NEW_FUTURE_EX (thread_safe , extra_size ) zend_async_future_create_fn(thread_safe, extra_size)
1396
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
+
1397
1428
END_EXTERN_C ()
1398
1429
1399
1430
#define ZEND_ASYNC_IS_ENABLED () zend_async_is_enabled()
0 commit comments