Class: ActiveSupport::Concurrency::ThreadMonitor
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/concurrency/thread_monitor.rb |
Constant Summary
-
EXCEPTION_IMMEDIATE =
private
# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 7{ Exception => :immediate }.freeze
-
EXCEPTION_NEVER =
private
# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 6{ Exception => :never }.freeze
Class Method Summary
- .new ⇒ ThreadMonitor constructor
Instance Method Summary
- #synchronize(&block)
- #mon_enter private
- #mon_exit private
- #mon_try_enter private
Constructor Details
.new ⇒ ThreadMonitor
# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 10
def initialize @owner = nil @count = 0 @mutex = Mutex.new end
Instance Method Details
#mon_enter (private)
[ GitHub ]# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 37
def mon_enter @mutex.lock if @owner != Thread.current @owner = Thread.current @count += 1 end
#mon_exit (private)
[ GitHub ]# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 43
def mon_exit unless @owner == Thread.current raise ThreadError, "current thread not owner" end @count -= 1 return unless @count == 0 @owner = nil @mutex.unlock end
#mon_try_enter (private)
[ GitHub ]# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 29
def mon_try_enter if @owner != Thread.current return false unless @mutex.try_lock @owner = Thread.current end @count += 1 end
#synchronize(&block)
[ GitHub ]# File 'activesupport/lib/active_support/concurrency/thread_monitor.rb', line 16
def synchronize(&block) Thread.handle_interrupt(EXCEPTION_NEVER) do mon_enter begin Thread.handle_interrupt(EXCEPTION_IMMEDIATE, &block) ensure mon_exit end end end