-
Notifications
You must be signed in to change notification settings - Fork 2
Fiber support #71
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Fiber support #71
Changes from 23 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
b44b96a
Refactor coroutine header includes: update fiber and async API depend…
EdmondDantes f26fbe2
Add basic fiber creation and execution test with active async scheduler
EdmondDantes b2e55d5
Add tests for fiber execution: simple return and suspend/resume cycles
EdmondDantes 9438aea
Add tests for multiple suspend/resume cycles and nested fibers
EdmondDantes d99e1fb
Add tests for Fiber exception handling and propagation
EdmondDantes d5e7812
+ Fiber status methods
EdmondDantes b7d8bff
Add tests for Fiber methods: getReturn, garbage collection, and handl…
EdmondDantes e73a1a6
Refactor Fiber garbage collection and NULL value handling
EdmondDantes f1736c2
Add fiber tests for independent coroutines
EdmondDantes 0a50c14
Add test for Fiber::getCoroutine() method
EdmondDantes 5d54ea0
Fix test: check ID > 0 instead of hardcoded value
EdmondDantes 5e9d05b
Fix test: remove regular fiber check - all fibers have coroutines
EdmondDantes 6e7ad68
+ tests for Revolt
EdmondDantes 1e0189c
Fix fiber garbage collection logic and update test expectations
EdmondDantes bf3fbc8
+ Fiber remains suspended after manager fiber terminates (event loop …
EdmondDantes edf53f7
Implement yield state tracking for fiber coroutines and update cancel…
EdmondDantes 4344c20
* send zend_create_graceful_exit() instead Cancellcation
EdmondDantes b67dc84
Add test for stream_select with null timeout in coroutine context
EdmondDantes c47ea0b
* fix bool libuv_reactor_execute(bool no_wait)
EdmondDantes 049b8f0
* fix bool libuv_reactor_execute(bool no_wait) + return has_handles &…
EdmondDantes 152833a
* fix edge cases
EdmondDantes f449138
add test for GC with include in suspended coroutine to check symTable…
EdmondDantes 5dad0ed
add tests for fiber cancellation scenarios and coroutine behavior
EdmondDantes 9e80d3f
* Fixed GC behavior during coroutine cancellation when an exception o…
EdmondDantes 01dd33a
* Update CHANGELOG.md
EdmondDantes File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
tests/edge_cases/011-gc_include_symtable_double_delref.phpt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| --TEST-- | ||
| GC with include in suspended coroutine - symTable double DELREF | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| use function Async\spawn; | ||
| use function Async\suspend; | ||
| use function Async\await; | ||
|
|
||
| class Cycle { | ||
| public $self; | ||
| } | ||
|
|
||
| try { | ||
| $coroutine = spawn(function() { | ||
| $parent1 = "value1"; | ||
| $parent2 = "value2"; | ||
|
|
||
| for ($i = 0; $i < 10000; $i++) { | ||
| $obj = new Cycle(); | ||
| $obj->self = $obj; | ||
| } | ||
|
|
||
| // Suspend - coroutine is now in suspended state | ||
| suspend(); | ||
|
|
||
| // Include inherits parent symTable | ||
| // Bug: GC may add same variables twice -> double DELREF | ||
| include __DIR__ . '/011-gc_include_symtable_double_delref_included.inc'; | ||
|
|
||
| echo "parent1: {$parent1}\n"; | ||
| echo "parent2: {$parent2}\n"; | ||
| echo "included: {$included}\n"; | ||
|
|
||
| return "done"; | ||
| }); | ||
|
|
||
| $result = await($coroutine); | ||
| echo "result: {$result}\n"; | ||
|
|
||
| } catch (Error $e) { | ||
| echo "Error: " . $e->getMessage() . "\n"; | ||
| } | ||
|
|
||
| echo "OK\n"; | ||
| gc_collect_cycles(); | ||
| ?> | ||
| --EXPECTF-- | ||
| parent1: value1 | ||
| parent2: value2 | ||
| included: included_value | ||
| result: done | ||
| OK |
3 changes: 3 additions & 0 deletions
3
tests/edge_cases/011-gc_include_symtable_double_delref_included.inc
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| <?php | ||
| // Included file for GC test | ||
| $included = "included_value"; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| --TEST-- | ||
| Fiber with coroutine: Basic fiber creation and execution when async is active | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| use function Async\spawn; | ||
| use function Async\await; | ||
|
|
||
| echo "Test: Fiber creation with active async scheduler\n"; | ||
|
|
||
| $coroutine = spawn(function() { | ||
| echo "Coroutine started\n"; | ||
|
|
||
| // Create a fiber while async scheduler is active | ||
| $fiber = new Fiber(function() { | ||
| echo "Fiber executing\n"; | ||
| return "fiber result"; | ||
| }); | ||
|
|
||
| echo "Starting fiber\n"; | ||
| $result = $fiber->start(); | ||
| echo "Fiber returned: " . $result . "\n"; | ||
|
|
||
| return "coroutine result"; | ||
| }); | ||
|
|
||
| $result = await($coroutine); | ||
| echo "Coroutine completed with: " . $result . "\n"; | ||
|
|
||
| echo "Test completed\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| Test: Fiber creation with active async scheduler | ||
| Coroutine started | ||
| Starting fiber | ||
| Fiber executing | ||
| Fiber returned: fiber result | ||
| Coroutine completed with: coroutine result | ||
| Test completed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| --TEST-- | ||
| Fiber with simple return without suspend | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| use function Async\spawn; | ||
| use function Async\await; | ||
|
|
||
| echo "Test: Fiber simple return without suspend\n"; | ||
|
|
||
| $coroutine = spawn(function() { | ||
| $fiber = new Fiber(function() { | ||
| echo "Fiber executing\n"; | ||
| return "result from fiber"; | ||
| }); | ||
|
|
||
| $result = $fiber->start(); | ||
| echo "Got: " . $result . "\n"; | ||
|
|
||
| return "coroutine done"; | ||
| }); | ||
|
|
||
| await($coroutine); | ||
| echo "Test completed\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| Test: Fiber simple return without suspend | ||
| Fiber executing | ||
| Got: result from fiber | ||
| Test completed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| --TEST-- | ||
| One suspend/resume cycle | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| use function Async\spawn; | ||
| use function Async\await; | ||
|
|
||
| echo "Test: One suspend/resume cycle\n"; | ||
|
|
||
| $coroutine = spawn(function() { | ||
| $fiber = new Fiber(function() { | ||
| echo "Before suspend\n"; | ||
| $value = Fiber::suspend("suspended"); | ||
| echo "After resume, got: " . $value . "\n"; | ||
| return "done"; | ||
| }); | ||
|
|
||
| $suspended = $fiber->start(); | ||
| echo "Fiber suspended with: " . $suspended . "\n"; | ||
|
|
||
| $result = $fiber->resume("resume value"); | ||
| echo "Fiber returned: " . $result . "\n"; | ||
|
|
||
| return "complete"; | ||
| }); | ||
|
|
||
| await($coroutine); | ||
| echo "Test completed\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| Test: One suspend/resume cycle | ||
| Before suspend | ||
| Fiber suspended with: suspended | ||
| After resume, got: resume value | ||
| Fiber returned: done | ||
| Test completed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| --TEST-- | ||
| Multiple suspend/resume cycles | ||
| --FILE-- | ||
| <?php | ||
|
|
||
| use function Async\spawn; | ||
| use function Async\await; | ||
|
|
||
| echo "Test: Multiple suspend/resume cycles\n"; | ||
|
|
||
| $coroutine = spawn(function() { | ||
| $fiber = new Fiber(function() { | ||
| $v1 = Fiber::suspend("suspend-1"); | ||
| echo "Got: " . $v1 . "\n"; | ||
|
|
||
| $v2 = Fiber::suspend("suspend-2"); | ||
| echo "Got: " . $v2 . "\n"; | ||
|
|
||
| $v3 = Fiber::suspend("suspend-3"); | ||
| echo "Got: " . $v3 . "\n"; | ||
|
|
||
| return "final"; | ||
| }); | ||
|
|
||
| echo "R1: " . $fiber->start() . "\n"; | ||
| echo "R2: " . $fiber->resume("resume-1") . "\n"; | ||
| echo "R3: " . $fiber->resume("resume-2") . "\n"; | ||
| echo "R4: " . $fiber->resume("resume-3") . "\n"; | ||
|
|
||
| return "done"; | ||
| }); | ||
|
|
||
| await($coroutine); | ||
| echo "Test completed\n"; | ||
| ?> | ||
| --EXPECT-- | ||
| Test: Multiple suspend/resume cycles | ||
| R1: suspend-1 | ||
| Got: resume-1 | ||
| R2: suspend-2 | ||
| Got: resume-2 | ||
| R3: suspend-3 | ||
| Got: resume-3 | ||
| R4: final | ||
| Test completed |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.