Skip to content

Commit 63e69a0

Browse files
committed
Enhance coroutine management: add filename and line tracking for new coroutines
1 parent 25dd603 commit 63e69a0

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

scheduler.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,22 @@ bool async_scheduler_coroutine_enqueue(zend_coroutine_t *coroutine)
10251025
} else {
10261026
coroutine->waker->status = ZEND_ASYNC_WAKER_QUEUED;
10271027

1028+
// Behavior for a new coroutine
1029+
// see: async_API.c spawn(zend_async_scope_t *scope, zend_object *scope_provider, int32_t priority)
1030+
if (false == ZEND_COROUTINE_IS_STARTED(coroutine)
1031+
&& zend_hash_index_find(&ASYNC_G(coroutines), ((async_coroutine_t *)coroutine)->std.handle) != NULL) {
1032+
// save the filename and line number where the coroutine was created
1033+
zend_apply_current_filename_and_line(&coroutine->filename, &coroutine->lineno);
1034+
1035+
if (UNEXPECTED(zend_hash_index_add_ptr(&ASYNC_G(coroutines), ((async_coroutine_t *)coroutine)->std.handle, coroutine) == NULL)) {
1036+
coroutine->waker->status = ZEND_ASYNC_WAKER_IGNORED;
1037+
async_throw_error("Failed to add coroutine to the list");
1038+
return NULL;
1039+
}
1040+
1041+
ZEND_ASYNC_INCREASE_COROUTINE_COUNT;
1042+
}
1043+
10281044
// Add to resumed_coroutines queue for event cleanup
10291045
if (ZEND_ASYNC_IS_SCHEDULER_CONTEXT) {
10301046
circular_buffer_push_ptr_with_resize(&ASYNC_G(resumed_coroutines), coroutine);

0 commit comments

Comments
 (0)