Skip to content

Commit 86f7879

Browse files
authored
Merge pull request #42 from true-async/41-xdebug-disruption
#41: add zend_observer_fiber_switch_notify when main coroutine create…
2 parents 46f2cdc + 78870b8 commit 86f7879

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

.clang-format

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
BasedOnStyle: WebKit
3+
SortIncludes: 'false'
4+
ColumnLimit: 100
5+
IndentWidth: 4
6+
TabWidth: 4
7+
ContinuationIndentWidth: 8
8+
UseTab: ForContinuationAndIndentation
9+
PointerAlignment: Right
10+
IndentCaseLabels: true
11+
AlignConsecutiveAssignments: false
12+
AlignEscapedNewlines: DontAlign
13+
AllowShortFunctionsOnASingleLine: false
14+
SpaceAfterCStyleCast: true
15+
AlignOperands: false
16+
...

scheduler.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
#include "exceptions.h"
2323
#include "scope.h"
2424
#include "zend_common.h"
25+
#include "zend_observer.h"
26+
27+
static zend_function main_coroutine_root_function = { ZEND_INTERNAL_FUNCTION };
2528

2629
void async_scheduler_startup(void)
2730
{
@@ -610,6 +613,19 @@ void async_scheduler_launch(void)
610613
main_transfer->flags = 0;
611614
ZVAL_NULL(&main_transfer->value);
612615

616+
//
617+
// Because the main coroutine is created on the fly, this code is here.
618+
// At the moment when PHP decides to activate the scheduler,
619+
// we must normalize the observer's state and notify it that we are creating the main coroutine.
620+
//
621+
// This code contains a logical conflict because main_transfer is, in a way, the context of the zero coroutine.
622+
// It's essentially a switch from the zero context to the coroutine context, even though,
623+
// logically, both contexts belong to the main execution thread.
624+
//
625+
main_coroutine->context.status = ZEND_FIBER_STATUS_INIT;
626+
zend_observer_fiber_switch_notify(main_transfer->context, &main_coroutine->context);
627+
main_coroutine->context.status = ZEND_FIBER_STATUS_RUNNING;
628+
613629
ASYNC_G(main_transfer) = main_transfer;
614630
ASYNC_G(main_vm_stack) = EG(vm_stack);
615631

0 commit comments

Comments
 (0)