Class: Dapp::Dimg::Lock::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dapp/dimg/lock/base.rb

Direct Known Subclasses

File

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ Base

Returns a new instance of Base.



7
8
9
10
# File 'lib/dapp/dimg/lock/base.rb', line 7

def initialize(name)
  @name = name
  @active_locks = 0
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/dapp/dimg/lock/base.rb', line 5

def name
  @name
end

Instance Method Details

#lock(timeout: 60, on_wait: nil, readonly: false) ⇒ Object



12
13
14
15
# File 'lib/dapp/dimg/lock/base.rb', line 12

def lock(timeout: 60, on_wait: nil, readonly: false)
  _do_lock(timeout, on_wait, readonly) unless @active_locks > 0
  @active_locks += 1
end

#synchronize(*args) ⇒ Object



22
23
24
25
26
27
28
29
# File 'lib/dapp/dimg/lock/base.rb', line 22

def synchronize(*args)
  lock(*args)
  begin
    yield if block_given?
  ensure
    unlock
  end
end

#unlockObject



17
18
19
20
# File 'lib/dapp/dimg/lock/base.rb', line 17

def unlock
  @active_locks -= 1
  _do_unlock if @active_locks.zero?
end