[前][次][番号順一覧][スレッド一覧]

ruby-changes:66621

From: Nobuyoshi <ko1@a...>
Date: Tue, 29 Jun 2021 13:32:47 +0900 (JST)
Subject: [ruby-changes:66621] 9eae8cdefb (master): Prefer qualified names under Thread

https://git.ruby-lang.org/ruby.git/commit/?id=9eae8cdefb

From 9eae8cdefba61e9e51feb30a4b98525593169666 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 28 Jun 2021 23:01:53 +0900
Subject: Prefer qualified names under Thread

---
 benchmark/vm_thread_condvar1.rb |  8 ++--
 benchmark/vm_thread_condvar2.rb | 10 ++---
 bootstraptest/test_insns.rb     |  2 +-
 bootstraptest/test_ractor.rb    |  2 +-
 lib/forwardable.rb              |  2 +-
 lib/mutex_m.rb                  | 12 ++---
 sample/drb/dchats.rb            |  2 +-
 test/fiber/scheduler.rb         | 10 +++--
 test/fiber/test_mutex.rb        | 18 ++++----
 test/monitor/test_monitor.rb    | 22 ++++-----
 test/ruby/test_bignum.rb        |  2 +-
 test/ruby/test_dir.rb           |  2 +-
 test/ruby/test_exception.rb     |  2 +-
 test/ruby/test_io.rb            |  2 +-
 test/ruby/test_process.rb       |  2 +-
 test/ruby/test_settracefunc.rb  |  8 ++--
 test/ruby/test_thread.rb        | 14 +++---
 test/ruby/test_thread_cv.rb     | 52 +++++++++++-----------
 test/ruby/test_thread_queue.rb  | 80 ++++++++++++++++-----------------
 test/test_pstore.rb             |  4 +-
 test/yaml/test_store.rb         |  4 +-
 thread.c                        |  2 +-
 thread_sync.c                   | 98 ++++++++++++++++++++---------------------
 23 files changed, 181 insertions(+), 179 deletions(-)

diff --git a/benchmark/vm_thread_condvar1.rb b/benchmark/vm_thread_condvar1.rb
index cf5706b..feed27c 100644
--- a/benchmark/vm_thread_condvar1.rb
+++ b/benchmark/vm_thread_condvar1.rb
@@ -1,9 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/vm_thread_condvar1.rb#L1
 # two threads, two mutex, two condvar ping-pong
 require 'thread'
-m1 = Mutex.new
-m2 = Mutex.new
-cv1 = ConditionVariable.new
-cv2 = ConditionVariable.new
+m1 = Thread::Mutex.new
+m2 = Thread::Mutex.new
+cv1 = Thread::ConditionVariable.new
+cv2 = Thread::ConditionVariable.new
 max = 100000
 i = 0
 wait = nil
diff --git a/benchmark/vm_thread_condvar2.rb b/benchmark/vm_thread_condvar2.rb
index 7c8dc19..6590c41 100644
--- a/benchmark/vm_thread_condvar2.rb
+++ b/benchmark/vm_thread_condvar2.rb
@@ -1,16 +1,16 @@ https://github.com/ruby/ruby/blob/trunk/benchmark/vm_thread_condvar2.rb#L1
 # many threads, one mutex, many condvars
 require 'thread'
-m = Mutex.new
-cv1 = ConditionVariable.new
-cv2 = ConditionVariable.new
+m = Thread::Mutex.new
+cv1 = Thread::ConditionVariable.new
+cv2 = Thread::ConditionVariable.new
 max = 1000
 n = 100
 waiting = 0
 scvs = []
 waiters = n.times.map do |i|
-  start_cv = ConditionVariable.new
+  start_cv = Thread::ConditionVariable.new
   scvs << start_cv
-  start_mtx = Mutex.new
+  start_mtx = Thread::Mutex.new
   start_mtx.synchronize do
     th = Thread.new(start_mtx, start_cv) do |sm, scv|
       m.synchronize do
diff --git a/bootstraptest/test_insns.rb b/bootstraptest/test_insns.rb
index 9052cad..31fdc29 100644
--- a/bootstraptest/test_insns.rb
+++ b/bootstraptest/test_insns.rb
@@ -384,7 +384,7 @@ tests = [ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_insns.rb#L384
   [ 'opt_empty_p', %q{ ''.empty? }, ],
   [ 'opt_empty_p', %q{ [].empty? }, ],
   [ 'opt_empty_p', %q{ {}.empty? }, ],
-  [ 'opt_empty_p', %q{ Queue.new.empty? }, ],
+  [ 'opt_empty_p', %q{ Thread::Queue.new.empty? }, ],
 
   [ 'opt_succ',  %q{ 1.succ == 2 }, ],
   if defined? $FIXNUM_MAX then
diff --git a/bootstraptest/test_ractor.rb b/bootstraptest/test_ractor.rb
index 80591f6..28c9e6d 100644
--- a/bootstraptest/test_ractor.rb
+++ b/bootstraptest/test_ractor.rb
@@ -533,7 +533,7 @@ assert_equal '[RuntimeError, "ok", true]', %q{ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_ractor.rb#L533
 # threads in a ractor will killed
 assert_equal '{:ok=>3}', %q{
   Ractor.new Ractor.current do |main|
-    q = Queue.new
+    q = Thread::Queue.new
     Thread.new do
       q << true
       loop{}
diff --git a/lib/forwardable.rb b/lib/forwardable.rb
index fb24b8c..c9c4128 100644
--- a/lib/forwardable.rb
+++ b/lib/forwardable.rb
@@ -76,7 +76,7 @@ https://github.com/ruby/ruby/blob/trunk/lib/forwardable.rb#L76
 #     def_delegators :@q, :clear, :first, :push, :shift, :size
 #   end
 #
-#   q = Queue.new
+#   q = Thread::Queue.new
 #   q.enq 1, 2, 3, 4, 5
 #   q.push 6
 #
diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb
index 18b6256..706d3c1 100644
--- a/lib/mutex_m.rb
+++ b/lib/mutex_m.rb
@@ -73,32 +73,32 @@ module Mutex_m https://github.com/ruby/ruby/blob/trunk/lib/mutex_m.rb#L73
     mu_initialize
   end
 
-  # See Mutex#synchronize
+  # See Thread::Mutex#synchronize
   def mu_synchronize(&block)
     @_mutex.synchronize(&block)
   end
 
-  # See Mutex#locked?
+  # See Thread::Mutex#locked?
   def mu_locked?
     @_mutex.locked?
   end
 
-  # See Mutex#try_lock
+  # See Thread::Mutex#try_lock
   def mu_try_lock
     @_mutex.try_lock
   end
 
-  # See Mutex#lock
+  # See Thread::Mutex#lock
   def mu_lock
     @_mutex.lock
   end
 
-  # See Mutex#unlock
+  # See Thread::Mutex#unlock
   def mu_unlock
     @_mutex.unlock
   end
 
-  # See Mutex#sleep
+  # See Thread::Mutex#sleep
   def sleep(timeout = nil)
     @_mutex.sleep(timeout)
   end
diff --git a/sample/drb/dchats.rb b/sample/drb/dchats.rb
index 58af3cf..c96486a 100644
--- a/sample/drb/dchats.rb
+++ b/sample/drb/dchats.rb
@@ -28,7 +28,7 @@ end https://github.com/ruby/ruby/blob/trunk/sample/drb/dchats.rb#L28
 
 class ChatServer
   def initialize
-    @mutex = Mutex.new
+    @mutex = Thread::Mutex.new
     @members = {}
   end
 
diff --git a/test/fiber/scheduler.rb b/test/fiber/scheduler.rb
index c844200..af64e4e 100644
--- a/test/fiber/scheduler.rb
+++ b/test/fiber/scheduler.rb
@@ -21,7 +21,7 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L21
 
     @closed = false
 
-    @lock = Mutex.new
+    @lock = Thread::Mutex.new
     @blocking = 0
     @ready = []
 
@@ -170,7 +170,7 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L170
     Fiber.yield
   end
 
-  # Used for Kernel#sleep and Mutex#sleep
+  # Used for Kernel#sleep and Thread::Mutex#sleep
   def kernel_sleep(duration = nil)
     # $stderr.puts [__method__, duration, Fiber.current].inspect
 
@@ -179,7 +179,8 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L179
     return true
   end
 
-  # Used when blocking on synchronization (Mutex#lock, Queue#pop, SizedQueue#push, ...)
+  # Used when blocking on synchronization (Thread::Mutex#lock,
+  # Thread::Queue#pop, Thread::SizedQueue#push, ...)
   def block(blocker, timeout = nil)
     # $stderr.puts [__method__, blocker, timeout].inspect
 
@@ -201,7 +202,8 @@ class Scheduler https://github.com/ruby/ruby/blob/trunk/test/fiber/scheduler.rb#L202
     end
   end
 
-  # Used when synchronization wakes up a previously-blocked fiber (Mutex#unlock, Queue#push, ...).
+  # Used when synchronization wakes up a previously-blocked fiber
+  # (Thread::Mutex#unlock, Thread::Queue#push, ...).
   # This might be called from another thread.
   def unblock(blocker, fiber)
     # $stderr.puts [__method__, blocker, fiber].inspect
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb
index 0842427..b0655f0 100644
--- a/test/fiber/test_mutex.rb
+++ b/test/fiber/test_mutex.rb
@@ -4,7 +4,7 @@ require_relative 'scheduler' https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L4
 
 class TestFiberMutex < Test::Unit::TestCase
   def test_mutex_synchronize
-    mutex = Mutex.new
+    mutex = Thread::Mutex.new
 
     thread = Thread.new do
       scheduler = Scheduler.new
@@ -23,7 +23,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L23
   end
 
   def test_mutex_interleaved_locking
-    mutex = Mutex.new
+    mutex = Thread::Mutex.new
 
     thread = Thread.new do
       scheduler = Scheduler.new
@@ -48,7 +48,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L48
   end
 
   def test_mutex_thread
-    mutex = Mutex.new
+    mutex = Thread::Mutex.new
     mutex.lock
 
     thread = Thread.new do
@@ -71,7 +71,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L71
   end
 
   def test_mutex_fiber_raise
-    mutex = Mutex.new
+    mutex = Thread::Mutex.new
     ran = false
 
     main = Thread.new do
@@ -103,8 +103,8 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L103
   end
 
   def test_condition_variable
-    mutex = Mutex.new
-    condition = ConditionVariable.new
+    mutex = Thread::Mutex.new
+    condition = Thread::ConditionVariable.new
 
     signalled = 0
 
@@ -138,7 +138,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L138
   end
 
   def test_queue
-    queue = Queue.new
+    queue = Thread::Queue.new
     processed = 0
 
     thread = Thread.new do
@@ -169,7 +169,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L169
   end
 
   def test_queue_pop_waits
-    queue = Queue.new
+    queue = Thread::Queue.new
     running = false
 
     thread = Thread.new do
@@ -198,7 +198,7 @@ class TestFiberMutex < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/fiber/test_mutex.rb#L198
 
     assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], error_pattern, success: false
     require 'scheduler'
-    mutex = Mutex.new
+    mutex = Thread::Mutex.new
 
     thread = Thread.new do
       scheduler = Scheduler.new
diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb
index 0f17d58..3eceee7 100644
--- a/test/monitor/test_monitor.rb
+++ b/test/monitor/test_monitor.rb
@@ -19,7 +19,7 @@ class TestMonitor < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/monitor/test_monitor.rb#L19
 
   def test_enter
     ary = []
-    queue = Queue.new
+    queue = Thread::Q (... truncated)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]