Skip to content

Commit d16d6b9

Browse files
authored
Merge pull request #77 from true-async/76-zend_async_scheduler_heartbeat
+ Added customizable scheduler heartbeat handler mechanism with `zend…
2 parents d911428 + e10ba76 commit d16d6b9

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1616
- Comprehensive test coverage for all fiber scenarios
1717
- **TrueAsync API**: Added `ZEND_ASYNC_SCHEDULER_LAUNCH()` macro for scheduler initialization
1818
- **TrueAsync API**: Updated to version 0.8.0 with fiber support
19+
- **TrueAsync API**: Added customizable scheduler heartbeat handler mechanism with `zend_async_set_heartbeat_handler()` API
1920

2021
### Fixed
2122
- **Critical GC Bug**: Fixed garbage collection crash during coroutine cancellation when exception occurs in main coroutine while GC is running

scheduler.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,8 @@ static zend_always_inline void scheduler_next_tick(void)
11251125
zend_object **exception_ptr = &EG(exception);
11261126
zend_object **prev_exception_ptr = &EG(prev_exception);
11271127

1128+
ZEND_ASYNC_SCHEDULER_HEARTBEAT;
1129+
11281130
execute_microtasks();
11291131
TRY_HANDLE_SUSPEND_EXCEPTION();
11301132

@@ -1195,8 +1197,6 @@ bool async_scheduler_coroutine_suspend(void)
11951197
}
11961198
}
11971199

1198-
ZEND_ASYNC_SCHEDULER_HEARTBEAT;
1199-
12001200
zend_coroutine_t *coroutine = ZEND_ASYNC_CURRENT_COROUTINE;
12011201

12021202
//
@@ -1330,6 +1330,7 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
13301330
// Allocate VM stack on C stack instead of heap
13311331
char vm_stack_memory[ZEND_FIBER_VM_STACK_SIZE];
13321332
bool *in_scheduler_context = &ZEND_ASYNC_SCHEDULER_CONTEXT;
1333+
zend_async_heartbeat_handler_t *heartbeat_handler = &ZEND_ASYNC_G(heartbeat_handler);
13331334

13341335
zend_first_try
13351336
{
@@ -1380,10 +1381,13 @@ ZEND_STACK_ALIGNED void fiber_entry(zend_fiber_transfer *transfer)
13801381

13811382
TRY_HANDLE_EXCEPTION();
13821383

1383-
ZEND_ASYNC_SCHEDULER_HEARTBEAT;
1384-
13851384
*in_scheduler_context = true;
13861385

1386+
//ZEND_ASYNC_SCHEDULER_HEARTBEAT;
1387+
if (*heartbeat_handler) {
1388+
(*heartbeat_handler)();
1389+
}
1390+
13871391
ZEND_ASSERT(circular_buffer_is_not_empty(resumed_coroutines) == 0 && "resumed_coroutines should be 0");
13881392

13891393
execute_microtasks();

tests/curl/005-error_handling.phpt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ $coroutines = [
8181
spawn(fn() => test_not_found($server)),
8282
];
8383

84-
$results = await_all($coroutines);
84+
[$results, $exceptions] = await_all($coroutines);
8585

8686
// Merge all outputs and sort by key to ensure deterministic order
8787
$all_output = [];
@@ -102,14 +102,14 @@ async_test_server_stop($server);
102102
--EXPECTF--
103103
Test start
104104
Testing connection error
105-
Testing server error
106-
Testing 404 error
107105
Connection failed as expected
108106
Error present: yes
109107
Error number: %d
108+
Testing server error
110109
HTTP Code: 500
111110
Error: none
112111
Response length: %d
112+
Testing 404 error
113113
HTTP Code: 404
114114
Response length: %d
115115
Test end

0 commit comments

Comments
 (0)