123456789_123456789_123456789_123456789_123456789_

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

Class Method Summary

Instance Method Summary

Constructor Details

.newThreadMonitor

[ GitHub ]

  
# 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