From caac5f777ae288b5982708b8690e712e1cae0cf6 Mon Sep 17 00:00:00 2001 From: Koichi Sasada Date: Sun, 20 Oct 2019 04:52:20 +0900 Subject: make monitor.so for performance. (#2576) Recent monitor.rb has performance problem because of interrupt handlers. 'Monitor#synchronize' is frequently used primitive so the performance of this method is important. This patch rewrite 'monitor.rb' with 'monitor.so' (C-extension) and make it faster. See [Feature #16255] for details. Monitor class objects are normal object which include MonitorMixin. This patch introduce a Monitor class which is implemented on C and MonitorMixin uses Monitor object as re-entrant (recursive) Mutex. This technique improve performance because we don't need to care atomicity and we don't need accesses to instance variables any more on Monitor class. --- test/monitor/test_monitor.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'test/monitor') diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb index 9d07bf75f7..49c34e067e 100644 --- a/test/monitor/test_monitor.rb +++ b/test/monitor/test_monitor.rb @@ -273,24 +273,24 @@ class TestMonitor < Test::Unit::TestCase end def test_wait_interruption - queue = Queue.new cond = @monitor.new_cond - @monitor.define_singleton_method(:mon_enter_for_cond) do |*args| - queue.deq - super(*args) - end + th = Thread.start { @monitor.synchronize do begin cond.wait(0.1) + @monitor.mon_owned? rescue Interrupt - @monitor.instance_variable_get(:@mon_owner) + @monitor.mon_owned? end end } sleep(0.1) th.raise(Interrupt) - queue.enq(nil) - assert_equal th, th.value + + begin + assert_equal true, th.value + rescue Interrupt + end end end -- cgit v1.2.3