Class: ProcessShared::Monitor

Inherits:
Mutex
  • Object
show all
Defined in:
lib/process_shared/monitor.rb

Instance Method Summary collapse

Methods inherited from Mutex

#locked?, #sleep, #synchronize, #try_lock

Methods included from OpenWithSelf

#open

Constructor Details

#initializeMonitor

Returns a new instance of Monitor


6
7
8
9
# File 'lib/process_shared/monitor.rb', line 6

def initialize
  super
  @lock_count = 0
end

Instance Method Details

#lockObject


11
12
13
14
15
16
17
# File 'lib/process_shared/monitor.rb', line 11

def lock
  if locked_by == current_process_and_thread
    @lock_count += 1
  else
    super
  end
end

#unlockObject


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/process_shared/monitor.rb', line 19

def unlock
  if locked_by == current_process_and_thread
    if @lock_count > 0
      @lock_count -= 1
    else
      super
    end
  else
    super
  end
end