-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement Fiber and Scheduler for win32
The actual stack context switch is still missing.
- Loading branch information
1 parent
f64c97a
commit 451c5ba
Showing
11 changed files
with
92 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,27 @@ | ||
require "c/winbase" | ||
require "c/winnt" | ||
require "c/processthreadsapi" | ||
|
||
module Crystal::System::Fiber | ||
def self.allocate_stack(stack_size) : Void* | ||
memory_pointer = LibC.VirtualAlloc(nil, stack_size, LibC::MEM_COMMIT | LibC::MEM_RESERVE, LibC::PAGE_READWRITE) | ||
|
||
if memory_pointer.null? | ||
raise WinError.new("VirtualAlloc") | ||
end | ||
|
||
memory_pointer | ||
end | ||
|
||
def self.free_stack(stack : Void*, stack_size) : Nil | ||
if LibC.VirtualFree(stack, stack_size, LibC::MEM_RELEASE) == 0 | ||
raise WinError.new("VirtualFree") | ||
end | ||
end | ||
|
||
def self.main_fiber_stack(stack_bottom : Void*) : Void* | ||
LibC.GetCurrentThreadStackLimits(out lowLimit, out highLimit) | ||
|
||
Pointer(Void).new(lowLimit) | ||
end | ||
end |
This file contains 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 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 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 |
---|---|---|
|
@@ -4,4 +4,5 @@ lib LibC | |
{% else %} | ||
alias ULONG_PTR = ULong | ||
{% end %} | ||
alias PULONG_PTR = ULONG_PTR* | ||
end |
This file contains 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,5 @@ | ||
require "./basetsd" | ||
|
||
lib LibC | ||
fun GetCurrentThreadStackLimits(lowLimit : PULONG_PTR, highLimit : PULONG_PTR) : Void | ||
end |
This file contains 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 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 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