Skip to content

Commit

Permalink
Fix: revert change to keep bytesize in stack
Browse files Browse the repository at this point in the history
  • Loading branch information
ysbaddaden committed Feb 10, 2025
1 parent 1f8eac0 commit 876434c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 15 deletions.
14 changes: 3 additions & 11 deletions src/fiber/stack.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,14 @@ class Fiber
# :nodoc:
struct Stack
getter pointer : Void*
getter bytesize : Int32
getter bottom : Void*
getter? reusable : Bool

def initialize(@pointer, bottom : Void*, *, @reusable = false)
@bytesize = (bottom - @pointer).to_i32
end

def initialize(@pointer, @bytesize, *, @reusable = false)
end

def bottom : Void*
@pointer + @bytesize
def initialize(@pointer, @bottom, *, @reusable = false)
end

def first_addressable_pointer : Void**
ptr = bottom # stacks grow down
ptr = @bottom # stacks grow down
ptr -= sizeof(Void*) # point to first addressable pointer
Pointer(Void*).new(ptr.address & ~15_u64) # align to 16 bytes
end
Expand Down
8 changes: 4 additions & 4 deletions src/fiber/stack_pool.cr
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Fiber

def finalize
@deque.each do |stack|
Crystal::System::Fiber.free_stack(stack.pointer, stack.bytesize)
Crystal::System::Fiber.free_stack(stack.pointer, STACK_SIZE)
end
end

Expand All @@ -26,7 +26,7 @@ class Fiber
def collect(count = lazy_size // 2) : Nil
count.times do
if stack = @deque.shift?
Crystal::System::Fiber.free_stack(stack.pointer, stack.bytesize)
Crystal::System::Fiber.free_stack(stack.pointer, STACK_SIZE)
else
return
end
Expand All @@ -43,11 +43,11 @@ class Fiber
# Removes a stack from the bottom of the pool, or allocates a new one.
def checkout : Stack
if stack = @deque.pop?
Crystal::System::Fiber.reset_stack(stack.pointer, stack.bytesize, @protect)
Crystal::System::Fiber.reset_stack(stack.pointer, STACK_SIZE, @protect)
stack
else
pointer = Crystal::System::Fiber.allocate_stack(STACK_SIZE, @protect)
Stack.new(pointer, STACK_SIZE, reusable: true)
Stack.new(pointer, pointer + STACK_SIZE, reusable: true)
end
end

Expand Down

0 comments on commit 876434c

Please sign in to comment.