@@ -60,7 +60,8 @@ static zend_class_entry * get_class_ce(zend_async_class type)
60
60
return NULL ;
61
61
}
62
62
63
- static zend_string * scheduler_module_name = NULL ;
63
+ static zend_atomic_bool scheduler_lock = {0 };
64
+ static char * scheduler_module_name = NULL ;
64
65
zend_async_spawn_t zend_async_spawn_fn = spawn ;
65
66
zend_async_new_coroutine_t zend_async_new_coroutine_fn = NULL ;
66
67
zend_async_new_scope_t zend_async_new_scope_fn = NULL ;
@@ -74,7 +75,8 @@ zend_async_add_microtask_t zend_async_add_microtask_fn = NULL;
74
75
zend_async_get_awaiting_info_t zend_async_get_awaiting_info_fn = NULL ;
75
76
zend_async_get_class_ce_t zend_async_get_class_ce_fn = get_class_ce ;
76
77
77
- static zend_string * reactor_module_name = NULL ;
78
+ static zend_atomic_bool reactor_lock = {0 };
79
+ static char * reactor_module_name = NULL ;
78
80
zend_async_reactor_startup_t zend_async_reactor_startup_fn = NULL ;
79
81
zend_async_reactor_shutdown_t zend_async_reactor_shutdown_fn = NULL ;
80
82
zend_async_reactor_execute_t zend_async_reactor_execute_fn = NULL ;
@@ -173,8 +175,8 @@ ZEND_API int zend_async_get_api_version_number(void)
173
175
return ZEND_ASYNC_API_VERSION_NUMBER ;
174
176
}
175
177
176
- ZEND_API void zend_async_scheduler_register (
177
- zend_string * module ,
178
+ ZEND_API bool zend_async_scheduler_register (
179
+ char * module ,
178
180
bool allow_override ,
179
181
zend_async_new_coroutine_t new_coroutine_fn ,
180
182
zend_async_new_scope_t new_scope_fn ,
@@ -191,19 +193,24 @@ ZEND_API void zend_async_scheduler_register(
191
193
zend_async_get_class_ce_t get_class_ce_fn
192
194
)
193
195
{
196
+ if (zend_atomic_bool_exchange (& scheduler_lock , 1 )) {
197
+ return false;
198
+ }
199
+
200
+ if (scheduler_module_name == module ) {
201
+ return true;
202
+ }
203
+
194
204
if (scheduler_module_name != NULL && false == allow_override ) {
205
+ zend_atomic_bool_store (& scheduler_lock , 0 );
195
206
zend_error (
196
207
E_CORE_ERROR , "The module %s is trying to override Scheduler, which was registered by the module %s." ,
197
- ZSTR_VAL ( module ), ZSTR_VAL ( scheduler_module_name )
208
+ module , scheduler_module_name
198
209
);
199
- return ;
210
+ return false ;
200
211
}
201
212
202
- if (scheduler_module_name != NULL ) {
203
- zend_string_release (scheduler_module_name );
204
- }
205
-
206
- scheduler_module_name = zend_string_copy (module );
213
+ scheduler_module_name = module ;
207
214
208
215
zend_async_new_coroutine_fn = new_coroutine_fn ;
209
216
zend_async_new_scope_fn = new_scope_fn ;
@@ -218,10 +225,14 @@ ZEND_API void zend_async_scheduler_register(
218
225
zend_async_add_microtask_fn = add_microtask_fn ;
219
226
zend_async_get_awaiting_info_fn = get_awaiting_info_fn ;
220
227
zend_async_get_class_ce_fn = get_class_ce_fn ;
228
+
229
+ zend_atomic_bool_store (& scheduler_lock , 0 );
230
+
231
+ return true;
221
232
}
222
233
223
- ZEND_API void zend_async_reactor_register (
224
- zend_string * module ,
234
+ ZEND_API bool zend_async_reactor_register (
235
+ char * module ,
225
236
bool allow_override ,
226
237
zend_async_reactor_startup_t reactor_startup_fn ,
227
238
zend_async_reactor_shutdown_t reactor_shutdown_fn ,
@@ -240,19 +251,23 @@ ZEND_API void zend_async_reactor_register(
240
251
zend_async_exec_t exec_fn
241
252
)
242
253
{
254
+ if (zend_atomic_bool_exchange (& reactor_lock , 1 )) {
255
+ return false;
256
+ }
257
+
258
+ if (reactor_module_name == module ) {
259
+ return true;
260
+ }
261
+
243
262
if (reactor_module_name != NULL && false == allow_override ) {
244
263
zend_error (
245
264
E_CORE_ERROR , "The module %s is trying to override Reactor, which was registered by the module %s." ,
246
- ZSTR_VAL ( module ), ZSTR_VAL ( reactor_module_name )
265
+ module , reactor_module_name
247
266
);
248
- return ;
267
+ return false ;
249
268
}
250
269
251
- if (reactor_module_name != NULL ) {
252
- zend_string_release (reactor_module_name );
253
- }
254
-
255
- reactor_module_name = zend_string_copy (module );
270
+ reactor_module_name = module ;
256
271
257
272
zend_async_reactor_startup_fn = reactor_startup_fn ;
258
273
zend_async_reactor_shutdown_fn = reactor_shutdown_fn ;
@@ -273,6 +288,10 @@ ZEND_API void zend_async_reactor_register(
273
288
274
289
zend_async_new_exec_event_fn = new_exec_event_fn ;
275
290
zend_async_exec_fn = exec_fn ;
291
+
292
+ zend_atomic_bool_store (& reactor_lock , 0 );
293
+
294
+ return true;
276
295
}
277
296
278
297
ZEND_API void zend_async_thread_pool_register (zend_string * module , bool allow_override , zend_async_queue_task_t queue_task_fn )
0 commit comments