From 4b298ad77a8388f0aae62daeca66659a8effeade Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 30 Aug 2016 06:22:30 +0000 Subject: [PATCH] Use qualified names git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56037 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- benchmark/bm_vm2_mutex.rb | 2 +- benchmark/bm_vm_thread_mutex1.rb | 2 +- benchmark/bm_vm_thread_mutex2.rb | 2 +- benchmark/bm_vm_thread_mutex3.rb | 2 +- benchmark/bm_vm_thread_queue.rb | 2 +- bootstraptest/test_objectspace.rb | 2 +- bootstraptest/test_thread.rb | 18 ++++++++-------- ext/digest/lib/digest.rb | 2 +- lib/debug.rb | 2 +- lib/drb/drb.rb | 4 ++-- lib/drb/extservm.rb | 2 +- lib/irb/workspace.rb | 2 +- lib/monitor.rb | 4 ++-- lib/mutex_m.rb | 2 +- lib/pstore.rb | 2 +- lib/resolv.rb | 8 +++---- lib/rinda/ring.rb | 2 +- lib/rinda/tuplespace.rb | 2 +- lib/shell.rb | 4 +--- lib/shell/process-controller.rb | 16 +++++++------- lib/shell/system-command.rb | 2 +- lib/singleton.rb | 2 +- lib/sync.rb | 2 +- lib/thwait.rb | 2 +- lib/tracer.rb | 2 +- lib/webrick/httpauth/digestauth.rb | 2 +- lib/webrick/httpauth/htdigest.rb | 2 +- lib/webrick/server.rb | 2 +- lib/webrick/utils.rb | 4 ++-- prelude.rb | 5 +++-- sample/drb/dhasen.rb | 2 +- sample/drb/dlogd.rb | 2 +- sample/drb/dqueue.rb | 2 +- sample/drb/http0serv.rb | 4 ++-- sample/drb/name.rb | 4 ++-- sample/philos.rb | 2 +- test/lib/minitest/unit.rb | 2 +- test/monitor/test_monitor.rb | 2 ++ test/ruby/lbtest.rb | 4 ++-- test/ruby/test_backtrace.rb | 4 ++-- test/ruby/test_file.rb | 4 ++-- test/ruby/test_regexp.rb | 2 +- test/ruby/test_thread.rb | 34 +++++++++++++++--------------- test/ruby/test_time.rb | 2 +- test/socket/test_unix.rb | 2 +- test/test_mutex_m.rb | 2 +- test/test_tempfile.rb | 4 ++-- test/test_timeout.rb | 2 +- test/thread/test_cv.rb | 3 +++ test/thread/test_queue.rb | 3 +++ 50 files changed, 100 insertions(+), 93 deletions(-) diff --git a/benchmark/bm_vm2_mutex.rb b/benchmark/bm_vm2_mutex.rb index 7362f738c5..5d16480c6b 100644 --- a/benchmark/bm_vm2_mutex.rb +++ b/benchmark/bm_vm2_mutex.rb @@ -1,6 +1,6 @@ require 'thread' -m = Mutex.new +m = Thread::Mutex.new i = 0 while i<6_000_000 # benchmark loop 2 diff --git a/benchmark/bm_vm_thread_mutex1.rb b/benchmark/bm_vm_thread_mutex1.rb index 5c9f85dfb7..66e42c85e1 100644 --- a/benchmark/bm_vm_thread_mutex1.rb +++ b/benchmark/bm_vm_thread_mutex1.rb @@ -1,7 +1,7 @@ # one thread, one mutex (no contention) require 'thread' -m = Mutex.new +m = Thread::Mutex.new r = 0 max = 2000 lmax = max * max diff --git a/benchmark/bm_vm_thread_mutex2.rb b/benchmark/bm_vm_thread_mutex2.rb index 10de59054f..6e6c804c31 100644 --- a/benchmark/bm_vm_thread_mutex2.rb +++ b/benchmark/bm_vm_thread_mutex2.rb @@ -1,7 +1,7 @@ # two threads, one mutex require 'thread' -m = Mutex.new +m = Thread::Mutex.new r = 0 max = 2000 lmax = (max * max)/2 diff --git a/benchmark/bm_vm_thread_mutex3.rb b/benchmark/bm_vm_thread_mutex3.rb index 7f9a44b39d..c750dc542a 100644 --- a/benchmark/bm_vm_thread_mutex3.rb +++ b/benchmark/bm_vm_thread_mutex3.rb @@ -1,7 +1,7 @@ # 1000 threads, one mutex require 'thread' -m = Mutex.new +m = Thread::Mutex.new r = 0 max = 2000 (1..max).map{ diff --git a/benchmark/bm_vm_thread_queue.rb b/benchmark/bm_vm_thread_queue.rb index 37381ae62b..274ceda366 100644 --- a/benchmark/bm_vm_thread_queue.rb +++ b/benchmark/bm_vm_thread_queue.rb @@ -1,7 +1,7 @@ require 'thread' n = 1_000_000 -q = Queue.new +q = Thread::Queue.new consumer = Thread.new{ while q.pop # consuming diff --git a/bootstraptest/test_objectspace.rb b/bootstraptest/test_objectspace.rb index 862a94e376..24a1a0ce2c 100644 --- a/bootstraptest/test_objectspace.rb +++ b/bootstraptest/test_objectspace.rb @@ -35,7 +35,7 @@ assert_normal_exit %q{ ObjectSpace.define_finalizer("") do - Mutex.new.lock + Thread::Mutex.new.lock end }, '[ruby-dev:44049]' diff --git a/bootstraptest/test_thread.rb b/bootstraptest/test_thread.rb index 747b6b88f7..d16295de8b 100644 --- a/bootstraptest/test_thread.rb +++ b/bootstraptest/test_thread.rb @@ -347,7 +347,7 @@ def m assert_equal 'ok', %q{ begin - m1, m2 = Mutex.new, Mutex.new + m1, m2 = Thread::Mutex.new, Thread::Mutex.new f1 = f2 = false Thread.new { m1.lock; f2 = true; sleep 0.001 until f1; m2.lock } m2.lock; f1 = true; sleep 0.001 until f2; m1.lock @@ -358,32 +358,32 @@ def m } assert_equal 'ok', %q{ - m = Mutex.new + m = Thread::Mutex.new Thread.new { m.lock }; sleep 0.1; m.lock :ok } assert_equal 'ok', %q{ - m = Mutex.new + m = Thread::Mutex.new Thread.new { m.lock }; m.lock :ok } assert_equal 'ok', %q{ - m = Mutex.new + m = Thread::Mutex.new Thread.new { m.lock }.join; m.lock :ok } assert_equal 'ok', %q{ - m = Mutex.new + m = Thread::Mutex.new Thread.new { m.lock; sleep 0.2 } sleep 0.1; m.lock :ok } assert_equal 'ok', %q{ - m = Mutex.new + m = Thread::Mutex.new Thread.new { m.lock; sleep 0.2; m.unlock } sleep 0.1; m.lock :ok @@ -409,7 +409,7 @@ def m open("zzz.rb", "w") do |f| f.puts <<-'end;' # do begin - m = Mutex.new + m = Thread::Mutex.new parent = Thread.current th1 = Thread.new { m.lock; sleep } sleep 0.01 until th1.stop? @@ -437,8 +437,8 @@ def m assert_finish 3, %q{ require 'thread' - lock = Mutex.new - cond = ConditionVariable.new + lock = Thread::Mutex.new + cond = Thread::ConditionVariable.new t = Thread.new do lock.synchronize do cond.wait(lock) diff --git a/ext/digest/lib/digest.rb b/ext/digest/lib/digest.rb index d6daf36f80..ba0637af32 100644 --- a/ext/digest/lib/digest.rb +++ b/ext/digest/lib/digest.rb @@ -3,7 +3,7 @@ module Digest # A mutex for Digest(). - REQUIRE_MUTEX = Mutex.new + REQUIRE_MUTEX = Thread::Mutex.new def self.const_missing(name) # :nodoc: case name diff --git a/lib/debug.rb b/lib/debug.rb index 5d754d8ebb..394a53e172 100644 --- a/lib/debug.rb +++ b/lib/debug.rb @@ -182,7 +182,7 @@ def Tracer.trace_func(*vars) # Debug is not available in safe mode. class DEBUGGER__ - MUTEX = Mutex.new # :nodoc: + MUTEX = Thread::Mutex.new # :nodoc: class Context # :nodoc: DEBUG_LAST_CMD = [] diff --git a/lib/drb/drb.rb b/lib/drb/drb.rb index f00e72c457..38cb38563b 100644 --- a/lib/drb/drb.rb +++ b/lib/drb/drb.rb @@ -1205,7 +1205,7 @@ def pretty_print_cycle(q) # :nodoc: # not normally need to deal with it directly. class DRbConn POOL_SIZE = 16 # :nodoc: - @mutex = Mutex.new + @mutex = Thread::Mutex.new @pool = [] def self.open(remote_uri) # :nodoc: @@ -1824,7 +1824,7 @@ def install_acl(acl) end module_function :install_acl - @mutex = Mutex.new + @mutex = Thread::Mutex.new def mutex # :nodoc: @mutex end diff --git a/lib/drb/extservm.rb b/lib/drb/extservm.rb index e2637aa62c..7e70a3cd82 100644 --- a/lib/drb/extservm.rb +++ b/lib/drb/extservm.rb @@ -28,7 +28,7 @@ def initialize @cond = new_cond @servers = {} @waiting = [] - @queue = Queue.new + @queue = Thread::Queue.new @thread = invoke_thread @uri = nil end diff --git a/lib/irb/workspace.rb b/lib/irb/workspace.rb index ac3e369430..16f714d66e 100644 --- a/lib/irb/workspace.rb +++ b/lib/irb/workspace.rb @@ -41,7 +41,7 @@ def initialize(*main) unless defined? BINDING_QUEUE require "thread" - IRB.const_set(:BINDING_QUEUE, SizedQueue.new(1)) + IRB.const_set(:BINDING_QUEUE, Thread::SizedQueue.new(1)) Thread.abort_on_exception = true Thread.start do eval "require \"irb/ws-for-case-2\"", TOPLEVEL_BINDING, __FILE__, __LINE__ diff --git a/lib/monitor.rb b/lib/monitor.rb index 73741f8ddb..3ded0b3658 100644 --- a/lib/monitor.rb +++ b/lib/monitor.rb @@ -153,7 +153,7 @@ def broadcast def initialize(monitor) @monitor = monitor - @cond = ::ConditionVariable.new + @cond = Thread::ConditionVariable.new end end @@ -241,7 +241,7 @@ def initialize(*args) def mon_initialize @mon_owner = nil @mon_count = 0 - @mon_mutex = Mutex.new + @mon_mutex = Thread::Mutex.new end def mon_check_owner diff --git a/lib/mutex_m.rb b/lib/mutex_m.rb index 627355151e..a8472f1582 100644 --- a/lib/mutex_m.rb +++ b/lib/mutex_m.rb @@ -102,7 +102,7 @@ def sleep(timeout = nil) private def mu_initialize # :nodoc: - @_mutex = Mutex.new + @_mutex = Thread::Mutex.new end def initialize(*args) # :nodoc: diff --git a/lib/pstore.rb b/lib/pstore.rb index 66a919e189..87153ed2cd 100644 --- a/lib/pstore.rb +++ b/lib/pstore.rb @@ -128,7 +128,7 @@ def initialize(file, thread_safe = false) @abort = false @ultra_safe = false @thread_safe = thread_safe - @lock = Mutex.new + @lock = Thread::Mutex.new end # Raises PStore::Error if the calling code is not in a PStore#transaction. diff --git a/lib/resolv.rb b/lib/resolv.rb index 9a981b99bd..ca4c7581ba 100644 --- a/lib/resolv.rb +++ b/lib/resolv.rb @@ -180,7 +180,7 @@ class Hosts def initialize(filename = DefaultFileName) @filename = filename - @mutex = Mutex.new + @mutex = Thread::Mutex.new @initialized = nil end @@ -334,7 +334,7 @@ def self.open(*args) # :ndots => 1) def initialize(config_info=nil) - @mutex = Mutex.new + @mutex = Thread::Mutex.new @config = Config.new(config_info) @initialized = nil end @@ -625,7 +625,7 @@ def self.rangerand(range) # :nodoc: end RequestID = {} # :nodoc: - RequestIDMutex = Mutex.new # :nodoc: + RequestIDMutex = Thread::Mutex.new # :nodoc: def self.allocate_request_id(host, port) # :nodoc: id = nil @@ -910,7 +910,7 @@ class RequestError < StandardError class Config # :nodoc: def initialize(config_info=nil) - @mutex = Mutex.new + @mutex = Thread::Mutex.new @config_info = config_info @initialized = nil @timeouts = nil diff --git a/lib/rinda/ring.rb b/lib/rinda/ring.rb index 9ec8a2fb2f..9b3f13eb93 100644 --- a/lib/rinda/ring.rb +++ b/lib/rinda/ring.rb @@ -385,7 +385,7 @@ def lookup_ring(timeout=5, &block) # TupleSpaces can be found by calling +to_a+. def lookup_ring_any(timeout=5) - queue = Queue.new + queue = Thread::Queue.new Thread.new do self.lookup_ring(timeout) do |ts| diff --git a/lib/rinda/tuplespace.rb b/lib/rinda/tuplespace.rb index e29bd63126..3ce8d2984f 100644 --- a/lib/rinda/tuplespace.rb +++ b/lib/rinda/tuplespace.rb @@ -246,7 +246,7 @@ class NotifyTemplateEntry < TemplateEntry def initialize(place, event, tuple, expires=nil) ary = [event, Rinda::Template.new(tuple)] super(ary, expires) - @queue = Queue.new + @queue = Thread::Queue.new @done = false end diff --git a/lib/shell.rb b/lib/shell.rb index 8216eb2862..b0bdc8194f 100644 --- a/lib/shell.rb +++ b/lib/shell.rb @@ -12,8 +12,6 @@ require "e2mmap" -require "thread" unless defined?(Mutex) - require "forwardable" require "shell/error" @@ -100,7 +98,7 @@ class Shell @debug_display_process_id = false @debug_display_thread_id = true - @debug_output_mutex = Mutex.new + @debug_output_mutex = Thread::Mutex.new class << Shell extend Forwardable diff --git a/lib/shell/process-controller.rb b/lib/shell/process-controller.rb index a100727aa6..a536ebd6ee 100644 --- a/lib/shell/process-controller.rb +++ b/lib/shell/process-controller.rb @@ -18,11 +18,11 @@ class Shell class ProcessController @ProcessControllers = {} - @ProcessControllersMonitor = Mutex.new - @ProcessControllersCV = ConditionVariable.new + @ProcessControllersMonitor = Thread::Mutex.new + @ProcessControllersCV = Thread::ConditionVariable.new - @BlockOutputMonitor = Mutex.new - @BlockOutputCV = ConditionVariable.new + @BlockOutputMonitor = Thread::Mutex.new + @BlockOutputCV = Thread::ConditionVariable.new class << self extend Forwardable @@ -97,8 +97,8 @@ def initialize(shell) @active_jobs = [] @jobs_sync = Sync.new - @job_monitor = Mutex.new - @job_condition = ConditionVariable.new + @job_monitor = Thread::Mutex.new + @job_condition = Thread::ConditionVariable.new end attr_reader :shell @@ -238,8 +238,8 @@ def sfork(command) pid = nil - pid_mutex = Mutex.new - pid_cv = ConditionVariable.new + pid_mutex = Thread::Mutex.new + pid_cv = Thread::ConditionVariable.new Thread.start do ProcessController.block_output_synchronize do diff --git a/lib/shell/system-command.rb b/lib/shell/system-command.rb index 2a8ffd6ed9..81456e7db3 100644 --- a/lib/shell/system-command.rb +++ b/lib/shell/system-command.rb @@ -22,7 +22,7 @@ def initialize(sh, command, *opts) @command = command @opts = opts - @input_queue = Queue.new + @input_queue = Thread::Queue.new @pid = nil sh.process_controller.add_schedule(self) diff --git a/lib/singleton.rb b/lib/singleton.rb index 2ee9b5b3b5..deb0f52cd6 100644 --- a/lib/singleton.rb +++ b/lib/singleton.rb @@ -133,7 +133,7 @@ class << Singleton # :nodoc: def __init__(klass) # :nodoc: klass.instance_eval { @singleton__instance__ = nil - @singleton__mutex__ = Mutex.new + @singleton__mutex__ = Thread::Mutex.new } def klass.instance # :nodoc: return @singleton__instance__ if @singleton__instance__ diff --git a/lib/sync.rb b/lib/sync.rb index ad6caf0743..c95343594f 100644 --- a/lib/sync.rb +++ b/lib/sync.rb @@ -261,7 +261,7 @@ def sync_initialize @sync_ex_locker = nil @sync_ex_count = 0 - @sync_mutex = Mutex.new + @sync_mutex = Thread::Mutex.new end def initialize(*args) diff --git a/lib/thwait.rb b/lib/thwait.rb index db7e6b1ce5..239915baef 100644 --- a/lib/thwait.rb +++ b/lib/thwait.rb @@ -51,7 +51,7 @@ def ThreadsWait.all_waits(*threads) # :yield: thread # def initialize(*threads) @threads = [] - @wait_queue = Queue.new + @wait_queue = Thread::Queue.new join_nowait(*threads) unless threads.empty? end diff --git a/lib/tracer.rb b/lib/tracer.rb index fd45f003c8..24a5313f4c 100644 --- a/lib/tracer.rb +++ b/lib/tracer.rb @@ -91,7 +91,7 @@ class << self Tracer::display_thread_id = true Tracer::display_c_call = false - @stdout_mutex = Mutex.new + @stdout_mutex = Thread::Mutex.new # Symbol table used for displaying trace information EVENT_SYMBOL = { diff --git a/lib/webrick/httpauth/digestauth.rb b/lib/webrick/httpauth/digestauth.rb index 98bdbd10c7..375ec20154 100644 --- a/lib/webrick/httpauth/digestauth.rb +++ b/lib/webrick/httpauth/digestauth.rb @@ -111,7 +111,7 @@ def initialize(config, default=Config::DigestAuth) @instance_key = hexdigest(self.__id__, Time.now.to_i, Process.pid) @opaques = {} @last_nonce_expire = Time.now - @mutex = Mutex.new + @mutex = Thread::Mutex.new end ## diff --git a/lib/webrick/httpauth/htdigest.rb b/lib/webrick/httpauth/htdigest.rb index 4bb25e1724..1ef4fdb4aa 100644 --- a/lib/webrick/httpauth/htdigest.rb +++ b/lib/webrick/httpauth/htdigest.rb @@ -38,7 +38,7 @@ def initialize(path) @path = path @mtime = Time.at(0) @digest = Hash.new - @mutex = Mutex::new + @mutex = Thread::Mutex::new @auth_type = DigestAuth open(@path,"a").close unless File::exist?(@path) reload diff --git a/lib/webrick/server.rb b/lib/webrick/server.rb index e2e99bfc5f..45bd9706d3 100644 --- a/lib/webrick/server.rb +++ b/lib/webrick/server.rb @@ -98,7 +98,7 @@ def initialize(config={}, default=Config::General) @config[:Logger] ||= Log::new @logger = @config[:Logger] - @tokens = SizedQueue.new(@config[:MaxClients]) + @tokens = Thread::SizedQueue.new(@config[:MaxClients]) @config[:MaxClients].times{ @tokens.push(nil) } webrickv = WEBrick::VERSION diff --git a/lib/webrick/utils.rb b/lib/webrick/utils.rb index 846829b01f..eb3b907ecf 100644 --- a/lib/webrick/utils.rb +++ b/lib/webrick/utils.rb @@ -126,7 +126,7 @@ class TimeoutHandler ## # Mutex used to synchronize access across threads - TimeoutMutex = Mutex.new # :nodoc: + TimeoutMutex = Thread::Mutex.new # :nodoc: ## # Registers a new timeout handler @@ -154,7 +154,7 @@ def initialize TimeoutMutex.synchronize{ @timeout_info = Hash.new } - @queue = Queue.new + @queue = Thread::Queue.new @watcher = nil end diff --git a/prelude.rb b/prelude.rb index 80f178d3bd..f9bb7451f8 100644 --- a/prelude.rb +++ b/prelude.rb @@ -1,5 +1,6 @@ class Thread - MUTEX_FOR_THREAD_EXCLUSIVE = Mutex.new # :nodoc: + MUTEX_FOR_THREAD_EXCLUSIVE = Thread::Mutex.new # :nodoc: + private_constant :MUTEX_FOR_THREAD_EXCLUSIVE # call-seq: # Thread.exclusive { block } => obj @@ -8,7 +9,7 @@ class Thread # value of the block. A thread executing inside the exclusive section will # only block other threads which also use the Thread.exclusive mechanism. def self.exclusive - warn "Thread.exclusive is deprecated, use Mutex", caller + warn "Thread.exclusive is deprecated, use Thread::Mutex", caller MUTEX_FOR_THREAD_EXCLUSIVE.synchronize{ yield } diff --git a/sample/drb/dhasen.rb b/sample/drb/dhasen.rb index 651b9c6c8a..9ab8534588 100644 --- a/sample/drb/dhasen.rb +++ b/sample/drb/dhasen.rb @@ -23,7 +23,7 @@ class Dhasen include DRbUndumped def initialize - @mutex = Mutex.new + @mutex = Thread::Mutex.new end def sparse(str, *arg) diff --git a/sample/drb/dlogd.rb b/sample/drb/dlogd.rb index 42f302e64e..be364511dc 100644 --- a/sample/drb/dlogd.rb +++ b/sample/drb/dlogd.rb @@ -10,7 +10,7 @@ class Logger def initialize(fname) @fname = fname.to_s @fp = File.open(@fname, "a+") - @queue = Queue.new + @queue = Thread::Queue.new @th = Thread.new { self.flush } end diff --git a/sample/drb/dqueue.rb b/sample/drb/dqueue.rb index 1c8878c080..1a405f5be5 100644 --- a/sample/drb/dqueue.rb +++ b/sample/drb/dqueue.rb @@ -6,7 +6,7 @@ require 'thread' require 'drb/drb' -DRb.start_service(nil, Queue.new) +DRb.start_service(nil, Thread::Queue.new) puts DRb.uri DRb.thread.join diff --git a/sample/drb/http0serv.rb b/sample/drb/http0serv.rb index 9503a1790c..049f5a1de5 100644 --- a/sample/drb/http0serv.rb +++ b/sample/drb/http0serv.rb @@ -18,7 +18,7 @@ class Callback < WEBrick::HTTPServlet::AbstractServlet def initialize(config, drb) @config = config @drb = drb - @queue = Queue.new + @queue = Thread::Queue.new end def do_POST(req, res) @@ -46,7 +46,7 @@ class Server def initialize(uri, config) @uri = uri @config = config - @queue = Queue.new + @queue = Thread::Queue.new setup_webrick(uri) end attr_reader :uri diff --git a/sample/drb/name.rb b/sample/drb/name.rb index 9527d47764..30c902b8f7 100644 --- a/sample/drb/name.rb +++ b/sample/drb/name.rb @@ -75,7 +75,7 @@ class Seq def initialize(v, name) @counter = v - @mutex = Mutex.new + @mutex = Thread::Mutex.new self.drb_name = name end @@ -90,7 +90,7 @@ def next_value class Front def initialize seq = Seq.new(0, 'seq') - mutex = Mutex.new + mutex = Thread::Mutex.new mutex.extend(DRbUndumped) mutex.extend(DRbNamedObject) mutex.drb_name = 'mutex' diff --git a/sample/philos.rb b/sample/philos.rb index 5c8f43c819..622e58b4bf 100644 --- a/sample/philos.rb +++ b/sample/philos.rb @@ -8,7 +8,7 @@ N=9 # number of philosophers $forks = [] for i in 0..N-1 - $forks[i] = Mutex.new + $forks[i] = Thread::Mutex.new end $state = "-o"*N diff --git a/test/lib/minitest/unit.rb b/test/lib/minitest/unit.rb index aa53ef06f6..b71e8b85b0 100644 --- a/test/lib/minitest/unit.rb +++ b/test/lib/minitest/unit.rb @@ -1008,7 +1008,7 @@ def initialize # :nodoc: @report = [] @errors = @failures = @skips = 0 @verbose = false - @mutex = defined?(Mutex) ? Mutex.new : nil + @mutex = Thread::Mutex.new @info_signal = Signal.list['INFO'] end diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb index 66c3e833ca..a3861735b3 100644 --- a/test/monitor/test_monitor.rb +++ b/test/monitor/test_monitor.rb @@ -5,6 +5,8 @@ require "test/unit" class TestMonitor < Test::Unit::TestCase + Queue = Thread::Queue + def setup @monitor = Monitor.new end diff --git a/test/ruby/lbtest.rb b/test/ruby/lbtest.rb index 591656af77..208c8b26ec 100644 --- a/test/ruby/lbtest.rb +++ b/test/ruby/lbtest.rb @@ -3,8 +3,8 @@ class LocalBarrier def initialize(n) - @wait = Queue.new - @done = Queue.new + @wait = Thread::Queue.new + @done = Thread::Queue.new @keeper = begin_keeper(n) end diff --git a/test/ruby/test_backtrace.rb b/test/ruby/test_backtrace.rb index b6b0f73882..ec6e0586d4 100644 --- a/test/ruby/test_backtrace.rb +++ b/test/ruby/test_backtrace.rb @@ -228,7 +228,7 @@ def th_rec q, n=10 def test_thread_backtrace begin - q = Queue.new + q = Thread::Queue.new th = Thread.new{ th_rec q } @@ -256,7 +256,7 @@ def test_thread_backtrace def test_thread_backtrace_locations_with_range begin - q = Queue.new + q = Thread::Queue.new th = Thread.new{ th_rec q } diff --git a/test/ruby/test_file.rb b/test/ruby/test_file.rb index f5a00f9e17..bd0e502f5b 100644 --- a/test/ruby/test_file.rb +++ b/test/ruby/test_file.rb @@ -121,8 +121,8 @@ def test_truncate_beyond_eof def test_truncate_size Tempfile.create("test-truncate") do |f| - q1 = Queue.new - q2 = Queue.new + q1 = Thread::Queue.new + q2 = Thread::Queue.new th = Thread.new do data = '' diff --git a/test/ruby/test_regexp.rb b/test/ruby/test_regexp.rb index 6cbfdb1a85..4853c41b86 100644 --- a/test/ruby/test_regexp.rb +++ b/test/ruby/test_regexp.rb @@ -1119,7 +1119,7 @@ def test_once_recursive end def test_once_multithread - m = Mutex.new + m = Thread::Mutex.new pr3 = proc{|i| /#{m.unlock; sleep 0.5; i}/o } diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index d1390d2bfa..9cb6a43cd5 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -96,7 +96,7 @@ def test_thread_variable_frozen end def test_mutex_synchronize - m = Mutex.new + m = Thread::Mutex.new r = 0 num_threads = 10 loop=100 @@ -120,7 +120,7 @@ def test_mutex_synchronize def test_mutex_synchronize_yields_no_block_params bug8097 = '[ruby-core:53424] [Bug #8097]' - assert_empty(Mutex.new.synchronize {|*params| break params}, bug8097) + assert_empty(Thread::Mutex.new.synchronize {|*params| break params}, bug8097) end def test_local_barrier @@ -346,8 +346,8 @@ def test_abort_on_exception def test_report_on_exception assert_separately([], <<~"end;") #do - q1 = Queue.new - q2 = Queue.new + q1 = Thread::Queue.new + q2 = Thread::Queue.new assert_equal(false, Thread.report_on_exception, "global flags is false by default") @@ -513,7 +513,7 @@ def test_select_wait end def test_mutex_deadlock - m = Mutex.new + m = Thread::Mutex.new m.synchronize do assert_raise(ThreadError) do m.synchronize do @@ -524,7 +524,7 @@ def test_mutex_deadlock end def test_mutex_interrupt - m = Mutex.new + m = Thread::Mutex.new m.lock t = Thread.new do m.lock @@ -536,7 +536,7 @@ def test_mutex_interrupt end def test_mutex_illegal_unlock - m = Mutex.new + m = Thread::Mutex.new m.lock assert_raise(ThreadError) do Thread.new do @@ -546,8 +546,8 @@ def test_mutex_illegal_unlock end def test_mutex_fifo_like_lock - m1 = Mutex.new - m2 = Mutex.new + m1 = Thread::Mutex.new + m2 = Thread::Mutex.new m1.lock m2.lock m1.unlock @@ -555,7 +555,7 @@ def test_mutex_fifo_like_lock assert_equal(false, m1.locked?) assert_equal(false, m2.locked?) - m3 = Mutex.new + m3 = Thread::Mutex.new m1.lock m2.lock m3.lock @@ -568,7 +568,7 @@ def test_mutex_fifo_like_lock end def test_mutex_trylock - m = Mutex.new + m = Thread::Mutex.new assert_equal(true, m.try_lock) assert_equal(false, m.try_lock, '[ruby-core:20943]') @@ -753,7 +753,7 @@ def test_handle_interrupt_and_p end def test_handle_interrupted? - q = Queue.new + q = Thread::Queue.new Thread.handle_interrupt(RuntimeError => :never){ done = false th = Thread.new{ @@ -902,7 +902,7 @@ def test_thread_join_main_thread def test_main_thread_status_at_exit assert_in_out_err([], <<-'INPUT', ["false false aborting"], []) require 'thread' -q = Queue.new +q = Thread::Queue.new Thread.new(Thread.current) {|mth| begin q.push nil @@ -969,7 +969,7 @@ def test_thread_status_raise_after_kill end def test_mutex_owned - mutex = Mutex.new + mutex = Thread::Mutex.new assert_equal(mutex.owned?, false) mutex.synchronize { @@ -981,7 +981,7 @@ def test_mutex_owned def test_mutex_owned2 begin - mutex = Mutex.new + mutex = Thread::Mutex.new th = Thread.new { # lock forever mutex.lock @@ -998,7 +998,7 @@ def test_mutex_owned2 def test_mutex_unlock_on_trap assert_in_out_err([], <<-INPUT, %w(locked unlocked false), []) - m = Mutex.new + m = Thread::Mutex.new trapped = false Signal.trap("INT") { |signo| @@ -1063,7 +1063,7 @@ def test_machine_stack_size def test_blocking_mutex_unlocked_on_fork bug8433 = '[ruby-core:55102] [Bug #8433]' - mutex = Mutex.new + mutex = Thread::Mutex.new flag = false mutex.lock diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb index c7d4487553..5a2ad42491 100644 --- a/test/ruby/test_time.rb +++ b/test/ruby/test_time.rb @@ -411,7 +411,7 @@ def o.to_int; 10; end end def test_time_interval - m = Mutex.new.lock + m = Thread::Mutex.new.lock assert_nothing_raised { Timeout.timeout(10) { m.sleep(0) diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb index 3fe7fb368b..7edb5e5d4f 100644 --- a/test/socket/test_unix.rb +++ b/test/socket/test_unix.rb @@ -142,7 +142,7 @@ def test_fd_passing_race_condition r1, w = IO.pipe s1, s2 = UNIXSocket.pair s1.nonblock = s2.nonblock = true - lock = Mutex.new + lock = Thread::Mutex.new nr = 0 x = 2 y = 1000 diff --git a/test/test_mutex_m.rb b/test/test_mutex_m.rb index e31c086f01..0365265b8c 100644 --- a/test/test_mutex_m.rb +++ b/test/test_mutex_m.rb @@ -8,7 +8,7 @@ def test_cv_wait o = Object.new o.instance_variable_set(:@foo, nil) o.extend(Mutex_m) - c = ConditionVariable.new + c = Thread::ConditionVariable.new t = Thread.start { o.synchronize do until foo = o.instance_variable_get(:@foo) diff --git a/test/test_tempfile.rb b/test/test_tempfile.rb index 815c243753..8147d93f85 100644 --- a/test/test_tempfile.rb +++ b/test/test_tempfile.rb @@ -246,8 +246,8 @@ def test_size_works_if_file_is_closed def test_concurrency threads = [] tempfiles = [] - lock = Mutex.new - cond = ConditionVariable.new + lock = Thread::Mutex.new + cond = Thread::ConditionVariable.new start = false 4.times do diff --git a/test/test_timeout.rb b/test/test_timeout.rb index 94ae83e820..1af61b7f8b 100644 --- a/test/test_timeout.rb +++ b/test/test_timeout.rb @@ -5,7 +5,7 @@ class TestTimeout < Test::Unit::TestCase def test_queue - q = Queue.new + q = Thread::Queue.new assert_raise(Timeout::Error, "[ruby-dev:32935]") { Timeout.timeout(0.01) { q.pop } } diff --git a/test/thread/test_cv.rb b/test/thread/test_cv.rb index 51afb0b08e..6779cb37ef 100644 --- a/test/thread/test_cv.rb +++ b/test/thread/test_cv.rb @@ -4,6 +4,9 @@ require 'tmpdir' class TestConditionVariable < Test::Unit::TestCase + ConditionVariable = Thread::ConditionVariable + Mutex = Thread::Mutex + def test_initialized assert_raise(TypeError) { ConditionVariable.allocate.wait(nil) diff --git a/test/thread/test_queue.rb b/test/thread/test_queue.rb index d2ab683c0c..cadc8e4d75 100644 --- a/test/thread/test_queue.rb +++ b/test/thread/test_queue.rb @@ -5,6 +5,9 @@ require 'timeout' class TestQueue < Test::Unit::TestCase + Queue = Thread::Queue + SizedQueue = Thread::SizedQueue + def test_queue_initialized assert_raise(TypeError) { Queue.allocate.push(nil) -- GitLab