@@ -139,6 +139,9 @@ typedef struct _zend_async_group_s zend_async_group_t;
139
139
typedef struct _zend_fcall_s zend_fcall_t ;
140
140
typedef void (* zend_coroutine_entry_t )(void );
141
141
142
+ /* The event loop additional handler function type */
143
+ typedef void (* zend_async_ev_handler_fn )(bool no_wait );
144
+
142
145
/* Channel method function types */
143
146
typedef bool (* zend_channel_send_t )(zend_async_channel_t * channel , zval * value );
144
147
typedef bool (* zend_channel_receive_t )(zend_async_channel_t * channel , zval * result );
@@ -1176,6 +1179,9 @@ typedef struct {
1176
1179
zend_coroutine_t * scheduler ;
1177
1180
/* Exit exception object */
1178
1181
zend_object * exit_exception ;
1182
+ /* An array of additional handlers for the EventLoop that will be invoked by the reactor */
1183
+ zend_async_ev_handler_fn ev_handlers [4 ]; /* Static array for event handlers */
1184
+ int ev_handlers_count ; /* Current number of handlers */
1179
1185
} zend_async_globals_t ;
1180
1186
1181
1187
BEGIN_EXTERN_C ()
@@ -1210,6 +1216,17 @@ END_EXTERN_C()
1210
1216
#define ZEND_ASYNC_MAIN_SCOPE ZEND_ASYNC_G(main_scope)
1211
1217
#define ZEND_ASYNC_SCHEDULER ZEND_ASYNC_G(scheduler)
1212
1218
1219
+ #define ZEND_ASYNC_EV_HANDLER_REGISTER (handler ) zend_async_ev_handler_register(handler)
1220
+ #define ZEND_ASYNC_EV_HANDLER_UNREGISTER (handler ) zend_async_ev_handler_unregister(handler)
1221
+
1222
+ /* Call all registered event loop handlers */
1223
+ #define ZEND_ASYNC_EV_HANDLERS_CALL (no_wait ) do { \
1224
+ int _count = ZEND_ASYNC_G(ev_handlers_count); \
1225
+ for (int _i = 0; _i < _count; _i++) { \
1226
+ ZEND_ASYNC_G(ev_handlers)[_i](no_wait); \
1227
+ } \
1228
+ } while (0)
1229
+
1213
1230
#define ZEND_ASYNC_INCREASE_EVENT_COUNT if (ZEND_ASYNC_G(active_event_count) < UINT_MAX) { \
1214
1231
ZEND_ASYNC_G(active_event_count)++; \
1215
1232
} else { \
@@ -1245,6 +1262,10 @@ void zend_async_api_shutdown(void);
1245
1262
void zend_async_globals_ctor (void );
1246
1263
void zend_async_globals_dtor (void );
1247
1264
1265
+ /* LibUv event loop handlers API */
1266
+ ZEND_API bool zend_async_ev_handler_register (zend_async_ev_handler_fn handler );
1267
+ ZEND_API bool zend_async_ev_handler_unregister (zend_async_ev_handler_fn handler );
1268
+
1248
1269
ZEND_API const char * zend_async_get_api_version (void );
1249
1270
ZEND_API int zend_async_get_api_version_number (void );
1250
1271
0 commit comments