From b9ca12657788f0345f7ada886e5de9b199923b59 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 7 Jan 2018 03:10:00 +0000 Subject: [PATCH] prelude.rb: eliminate a private constant * prelude.rb (Thread.exclusive): eliminate a private constant, MUTEX_FOR_THREAD_EXCLUSIVE. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61644 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- prelude.rb | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/prelude.rb b/prelude.rb index 7cfe0892b3..9e94aadf9c 100644 --- a/prelude.rb +++ b/prelude.rb @@ -1,16 +1,15 @@ -class Thread - MUTEX_FOR_THREAD_EXCLUSIVE = Thread::Mutex.new # :nodoc: - private_constant :MUTEX_FOR_THREAD_EXCLUSIVE - +class << Thread # call-seq: # Thread.exclusive { block } => obj # # Wraps the block in a single, VM-global Mutex.synchronize, returning the # 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(&block) + def exclusive(&block) end if false + mutex = Mutex.new # :nodoc: + define_method(:exclusive) do |&block| warn "Thread.exclusive is deprecated, use Thread::Mutex", caller - MUTEX_FOR_THREAD_EXCLUSIVE.synchronize(&block) + mutex.synchronize(&block) end end