-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
RFC 2: Skeleton for ExecutionContext #15350
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
straight-shoota
merged 16 commits into
crystal-lang:master
from
ysbaddaden:feature/execution-context-skeleton
Feb 22, 2025
Merged
Changes from 3 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
3e14951
Skeleton for ExecutionContext types as per RFC #0002
ysbaddaden 35da3f9
Add thread safety to Fiber::StackPool
ysbaddaden 3852ce4
Alt EventLoop#run(queue*, blocking) method
ysbaddaden 0683695
Fix: wrong documentation for ExecutionContext#enqueue
ysbaddaden 8abce65
Document Thread#dead_fiber (delayed fiber stack cleanup)
ysbaddaden 7f2d0d4
Fix: move require crystal/system/print_error to src/raise
ysbaddaden 094393c
Rename as Fiber::ExecutionContext + add :nodoc:
ysbaddaden 0e86c55
Fix: handle dead fiber stack out of swapcontext
ysbaddaden ce23a0e
Fix: compilation with Thread dead_fiber_stack
ysbaddaden 95718e6
Fixup: can't infer type of ivar declared in macro (stack pool lock)
ysbaddaden f6e11e2
fixup! Fixup: can't infer type of ivar declared in macro (stack pool …
ysbaddaden f15e6bc
Merge remote-tracking branch 'upstream/master' into feature/execution…
ysbaddaden b72f07e
Fix: explicit type for Fiber.new (not inferred because inside macro?)
ysbaddaden 2d6e474
fixup! Alt EventLoop#run(queue*, blocking) method
ysbaddaden d3af76b
Fix: dead fiber stack
ysbaddaden b5c0c8e
Fix: Fiber.new
ysbaddaden 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -112,14 +112,25 @@ abstract class Crystal::EventLoop::Polling < Crystal::EventLoop | |
end | ||
{% end %} | ||
|
||
# NOTE: thread unsafe | ||
# thread unsafe | ||
def run(blocking : Bool) : Bool | ||
system_run(blocking) do |fiber| | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% if flag?(:execution_context) %} | ||
fiber.execution_context.enqueue(fiber) | ||
{% else %} | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% end %} | ||
end | ||
true | ||
end | ||
|
||
{% if flag?(:execution_context) %} | ||
# thread unsafe | ||
def run(queue : Fiber::Queue*, blocking : Bool) : Nil | ||
system_run(blocking) { |fiber| queue.value.push(fiber) } | ||
end | ||
{% end %} | ||
|
||
# fiber interface, see Crystal::EventLoop | ||
|
||
def create_resume_event(fiber : Fiber) : FiberEvent | ||
|
@@ -303,13 +314,21 @@ abstract class Crystal::EventLoop::Polling < Crystal::EventLoop | |
Polling.arena.free(index) do |pd| | ||
[email protected]_all do |event| | ||
pd.value.@event_loop.try(&.unsafe_resume_io(event) do |fiber| | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% if flag?(:execution_context) %} | ||
fiber.execution_context.enqueue(fiber) | ||
{% else %} | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% end %} | ||
end) | ||
end | ||
|
||
[email protected]_all do |event| | ||
pd.value.@event_loop.try(&.unsafe_resume_io(event) do |fiber| | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% if flag?(:execution_context) %} | ||
fiber.execution_context.enqueue(fiber) | ||
{% else %} | ||
Crystal::Scheduler.enqueue(fiber) | ||
{% end %} | ||
end) | ||
end | ||
|
||
|
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
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.