ruby-changes:63035
From: Benoit <ko1@a...>
Date: Mon, 21 Sep 2020 23:06:57 +0900 (JST)
Subject: [ruby-changes:63035] 2b73e6ba71 (master): Simplify the implementation of Scheduler#block
https://git.ruby-lang.org/ruby.git/commit/?id=2b73e6ba71 From 2b73e6ba712d35e6ec767bf722edf542cc2e47c6 Mon Sep 17 00:00:00 2001 From: Benoit Daloze <eregontp@g...> Date: Mon, 21 Sep 2020 16:04:20 +0200 Subject: Simplify the implementation of Scheduler#block * This shows block() with a timeout is similar to #kernel_sleep and also does not need to change `@blocking`. diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb index d93d0f1..c685e6f 100644 --- a/test/fiber/scheduler.rb +++ b/test/fiber/scheduler.rb @@ -102,8 +102,8 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L102 self.run ensure @closed = true - - # We freeze to detect any inadvertant modifications after the scheduler is closed: + + # We freeze to detect any unintended modifications after the scheduler is closed: self.freeze end @@ -144,19 +144,21 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L144 # Used when blocking on synchronization (Mutex#lock, Queue#pop, SizedQueue#push, ...) def block(blocker, timeout = nil) # p [__method__, blocker, timeout] - @blocking += 1 - if timeout @waiting[Fiber.current] = current_time + timeout - end - - Fiber.yield - ensure - @blocking -= 1 - - # Remove from @waiting in the case #unblock was called before the timeout expired: - if timeout - @waiting.delete(Fiber.current) + begin + Fiber.yield + ensure + # Remove from @waiting in the case #unblock was called before the timeout expired: + @waiting.delete(Fiber.current) + end + else + @blocking += 1 + begin + Fiber.yield + ensure + @blocking -= 1 + end end end -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/