diff --git a/spec/std/crystal/event_loop/polling/poll_descriptor_spec.cr b/spec/std/crystal/event_loop/polling/poll_descriptor_spec.cr index 04c090e7b83f..6227ad57028e 100644 --- a/spec/std/crystal/event_loop/polling/poll_descriptor_spec.cr +++ b/spec/std/crystal/event_loop/polling/poll_descriptor_spec.cr @@ -8,7 +8,7 @@ class Crystal::EventLoop::FakeLoop < Crystal::EventLoop::Polling private def system_run(blocking : Bool, & : Fiber ->) : Nil end - private def interrupt : Nil + def interrupt : Nil end protected def system_add(fd : Int32, index : Arena::Index) : Nil diff --git a/src/crystal/fiber_channel.cr b/src/crystal/fiber_channel.cr deleted file mode 100644 index dbe0cc6187b9..000000000000 --- a/src/crystal/fiber_channel.cr +++ /dev/null @@ -1,23 +0,0 @@ -# :nodoc: -# -# This struct wraps around a IO pipe to send and receive fibers between -# worker threads. The receiving thread will hang on listening for new fibers -# or fibers that become runnable by the execution of other threads, at the same -# time it waits for other IO events or timers within the event loop -struct Crystal::FiberChannel - @worker_in : IO::FileDescriptor - @worker_out : IO::FileDescriptor - - def initialize - @worker_out, @worker_in = IO.pipe - end - - def send(fiber : Fiber) - @worker_in.write_bytes(fiber.object_id) - end - - def receive - oid = @worker_out.read_bytes(UInt64) - Pointer(Fiber).new(oid).as(Fiber) - end -end diff --git a/src/crystal/scheduler.cr b/src/crystal/scheduler.cr index 9b64823f3905..ad0f2a55672e 100644 --- a/src/crystal/scheduler.cr +++ b/src/crystal/scheduler.cr @@ -1,6 +1,5 @@ require "crystal/event_loop" require "crystal/system/print_error" -require "./fiber_channel" require "fiber" require "fiber/stack_pool" require "crystal/system/thread" @@ -97,10 +96,6 @@ class Crystal::Scheduler {% end %} end - {% if flag?(:preview_mt) %} - private getter(fiber_channel : Crystal::FiberChannel) { Crystal::FiberChannel.new } - {% end %} - @main : Fiber @lock = Crystal::SpinLock.new @sleeping = false @@ -180,6 +175,7 @@ class Crystal::Scheduler end {% if flag?(:preview_mt) %} + private getter! worker_fiber : Fiber @rr_target = 0 protected def find_target_thread @@ -192,38 +188,34 @@ class Crystal::Scheduler end def run_loop + @worker_fiber = Fiber.current + spawn_stack_pool_collector - fiber_channel = self.fiber_channel loop do @lock.lock if runnable = @runnables.shift? - @runnables << Fiber.current + @runnables << worker_fiber @lock.unlock resume(runnable) else @sleeping = true @lock.unlock - Crystal.trace :sched, "mt:sleeping" - fiber = Crystal.trace(:sched, "mt:slept") { fiber_channel.receive } - - @lock.lock - @sleeping = false - @runnables << Fiber.current - @lock.unlock - resume(fiber) + Crystal.trace(:sched, "mt:slept") { ::Fiber.suspend } end end end def send_fiber(fiber : Fiber) @lock.lock + @runnables << fiber + if @sleeping - fiber_channel.send(fiber) - else - @runnables << fiber + @sleeping = false + @runnables << worker_fiber + @event_loop.interrupt end @lock.unlock end