From dd2e95fb26b89ce060631af0fd372b5780a443dd Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Thu, 1 Oct 2020 13:44:23 +1300 Subject: [PATCH] Remove `Thread.scheduler` from public interface. It's implementation is equivalent to: Thread.current.scheduler unless Thread.current.blocking? --- test/fiber/test_mutex.rb | 13 ++++++------- thread.c | 2 +- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb index 258f5358a6..c38d45b189 100644 --- a/test/fiber/test_mutex.rb +++ b/test/fiber/test_mutex.rb @@ -11,10 +11,10 @@ class TestFiberMutex < Test::Unit::TestCase Thread.current.scheduler = scheduler Fiber.schedule do - assert_equal Thread.scheduler, scheduler + refute Thread.current.blocking? mutex.synchronize do - assert Thread.scheduler + refute Thread.current.blocking? end end end @@ -83,9 +83,9 @@ class TestFiberMutex < Test::Unit::TestCase f = Fiber.schedule do assert_raise_with_message(RuntimeError, "bye") do - assert_same scheduler, Thread.scheduler mutex.lock end + ran = true end @@ -196,8 +196,9 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_deadlock - err = /No live threads left. Deadlock\?/ - assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], err, success: false + error_pattern = /No live threads left. Deadlock\?/ + + assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], error_pattern, success: false require 'scheduler' mutex = Mutex.new @@ -206,8 +207,6 @@ class TestFiberMutex < Test::Unit::TestCase Thread.current.scheduler = scheduler Fiber.schedule do - raise unless Thread.scheduler == scheduler - mutex.synchronize do puts 'in synchronize' Fiber.yield diff --git a/thread.c b/thread.c index 510d8a028b..3aca71dd6c 100644 --- a/thread.c +++ b/thread.c @@ -5519,7 +5519,7 @@ Init_Thread(void) rb_define_method(rb_cThread, "backtrace", rb_thread_backtrace_m, -1); rb_define_method(rb_cThread, "backtrace_locations", rb_thread_backtrace_locations_m, -1); - rb_define_singleton_method(rb_cThread, "scheduler", rb_thread_scheduler, 0); + // rb_define_singleton_method(rb_cThread, "scheduler", rb_thread_scheduler, 0); rb_define_method(rb_cThread, "scheduler", rb_thread_scheduler_get, 0); rb_define_method(rb_cThread, "scheduler=", rb_thread_scheduler_set, 1);