Class: Dapp::Dimg::Lock::Base
- Inherits:
-
Object
- Object
- Dapp::Dimg::Lock::Base
- Defined in:
- lib/dapp/dimg/lock/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
-
#initialize(name) ⇒ Base
constructor
A new instance of Base.
- #lock(timeout: 60, on_wait: nil, readonly: false) ⇒ Object
- #synchronize(*args) ⇒ Object
- #unlock ⇒ Object
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
#name ⇒ Object (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 |
#unlock ⇒ Object
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 |