From 876434c87b4be32c276ed485ba29d76b71f28685 Mon Sep 17 00:00:00 2001 From: Julien Portalier Date: Mon, 10 Feb 2025 16:50:15 +0100 Subject: [PATCH] Fix: revert change to keep bytesize in stack --- src/fiber/stack.cr | 14 +++----------- src/fiber/stack_pool.cr | 8 ++++---- 2 files changed, 7 insertions(+), 15 deletions(-) diff --git a/src/fiber/stack.cr b/src/fiber/stack.cr index fb0384ab3445..9666b506db0c 100644 --- a/src/fiber/stack.cr +++ b/src/fiber/stack.cr @@ -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 diff --git a/src/fiber/stack_pool.cr b/src/fiber/stack_pool.cr index d88e20050ce3..04954de40a94 100644 --- a/src/fiber/stack_pool.cr +++ b/src/fiber/stack_pool.cr @@ -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 @@ -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 @@ -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