ruby-changes:63544
From: Samuel <ko1@a...>
Date: Sun, 8 Nov 2020 16:41:13 +0900 (JST)
Subject: [ruby-changes:63544] bed4848661 (master): Urgent notification pipe has same lifetime as scheduler.
https://git.ruby-lang.org/ruby.git/commit/?id=bed4848661 From bed4848661d4a0397b36f481c0c0940277cc31f8 Mon Sep 17 00:00:00 2001 From: Samuel Williams <samuel.williams@o...> Date: Sun, 8 Nov 2020 19:55:27 +1300 Subject: Urgent notification pipe has same lifetime as scheduler. diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index 8879048..7cf0c26 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -25,7 +25,7 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L25 @blocking = 0 @ready = [] - @urgent = nil + @urgent = IO.pipe end attr :readable @@ -47,8 +47,6 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L47 end def run - @urgent = IO.pipe - while @readable.any? or @writable.any? or @waiting.any? or @blocking.positive? # Can only handle file descriptors up to 1024... readable, writable = IO.select(@readable.keys + [@urgent.first], @writable.keys, [], next_timeout) @@ -95,9 +93,6 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L93 end end end - ensure - @urgent.each(&:close) - @urgent = nil end def close @@ -105,6 +100,9 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L100 self.run ensure + @urgent.each(&:close) + @urgent = nil + @closed = true # We freeze to detect any unintended modifications after the scheduler is closed: @@ -142,7 +140,8 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L140 # Used when blocking on synchronization (Mutex#lock, Queue#pop, SizedQueue#push, ...) def block(blocker, timeout = nil) - # p [__method__, blocker, timeout] + # $stderr.puts [__method__, blocker, timeout].inspect + if timeout @waiting[Fiber.current] = current_time + timeout begin @@ -164,14 +163,14 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L163 # Used when synchronization wakes up a previously-blocked fiber (Mutex#unlock, Queue#push, ...). # This might be called from another thread. def unblock(blocker, fiber) - # p [__method__, blocker, fiber] + # $stderr.puts [__method__, blocker, fiber].inspect + @lock.synchronize do @ready << fiber end - if io = @urgent&.last - io.write_nonblock('.') - end + io = @urgent.last + io.write_nonblock('.') end def fiber(&block) -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/