Class: Spinoza::LockManager::ReadLock
- Inherits:
-
Object
- Object
- Spinoza::LockManager::ReadLock
- Defined in:
- lib/spinoza/system/lock-manager.rb
Overview
State of lock on one resource (e.g., a row), which may be held concurrently by any number of threads. Reentrant.
Instance Attribute Summary collapse
-
#txns ⇒ Object
readonly
Returns the value of attribute txns.
Instance Method Summary collapse
- #add(txn) ⇒ Object
- #includes?(txn) ⇒ Boolean
-
#initialize(txn) ⇒ ReadLock
constructor
A new instance of ReadLock.
- #remove(txn) ⇒ Object
- #unlocked? ⇒ Boolean
Constructor Details
#initialize(txn) ⇒ ReadLock
Returns a new instance of ReadLock.
21 22 23 24 |
# File 'lib/spinoza/system/lock-manager.rb', line 21 def initialize txn @txns = Hash.new(0) add txn end |
Instance Attribute Details
#txns ⇒ Object (readonly)
Returns the value of attribute txns.
19 20 21 |
# File 'lib/spinoza/system/lock-manager.rb', line 19 def txns @txns end |
Instance Method Details
#add(txn) ⇒ Object
34 35 36 |
# File 'lib/spinoza/system/lock-manager.rb', line 34 def add txn @txns[txn] += 1 end |
#includes?(txn) ⇒ Boolean
30 31 32 |
# File 'lib/spinoza/system/lock-manager.rb', line 30 def includes? txn @txns[txn] > 0 end |
#remove(txn) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/spinoza/system/lock-manager.rb', line 38 def remove txn if includes? txn @txns[txn] -= 1 @txns.delete txn if @txns[txn] == 0 else raise ConcurrencyError, "#{self} is not locked by #{txn}" end end |
#unlocked? ⇒ Boolean
26 27 28 |
# File 'lib/spinoza/system/lock-manager.rb', line 26 def unlocked? @txns.all? {|t,c| c == 0} end |