Skip to content

Commit b8832ec

Browse files
committed
#53: Add to scheduler.c logic Waker clean after EventLoop tick
1 parent f3c4348 commit b8832ec

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

scheduler.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
12951295
bool was_executed = false;
12961296
switch_status status = COROUTINE_NOT_EXISTS;
12971297

1298+
const circular_buffer_t * coroutine_queue = &ASYNC_G(coroutine_queue);
1299+
12981300
do {
12991301

13001302
TRY_HANDLE_EXCEPTION();
@@ -1306,8 +1308,18 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
13061308
execute_microtasks();
13071309
TRY_HANDLE_EXCEPTION();
13081310

1309-
has_next_coroutine = circular_buffer_is_not_empty(&ASYNC_G(coroutine_queue));
1311+
const void *previous_data = coroutine_queue->data;
1312+
const size_t previous_count = circular_buffer_count(coroutine_queue);
1313+
const size_t previous_head = coroutine_queue->head;
1314+
1315+
has_next_coroutine = previous_count > 0;
1316+
13101317
has_handles = ZEND_ASYNC_REACTOR_EXECUTE(has_next_coroutine);
1318+
1319+
if (previous_head != coroutine_queue->head) {
1320+
clean_events_for_resumed_coroutines(coroutine_queue, previous_data, previous_count, previous_head);
1321+
}
1322+
13111323
TRY_HANDLE_EXCEPTION();
13121324

13131325
ZEND_ASYNC_SCHEDULER_CONTEXT = false;
@@ -1349,7 +1361,7 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
13491361

13501362
if (UNEXPECTED(false == has_handles && false == was_executed &&
13511363
zend_hash_num_elements(&ASYNC_G(coroutines)) > 0 &&
1352-
circular_buffer_is_empty(&ASYNC_G(coroutine_queue)) &&
1364+
circular_buffer_is_empty(coroutine_queue) &&
13531365
circular_buffer_is_empty(&ASYNC_G(microtasks)) && resolve_deadlocks())) {
13541366
break;
13551367
}

0 commit comments

Comments
 (0)