Class: Spinoza::LockManager::WriteLock
- Inherits:
-
Object
- Object
- Spinoza::LockManager::WriteLock
- 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 at most one thread. Reentrant.
Instance Attribute Summary collapse
-
#count ⇒ Object
readonly
Returns the value of attribute count.
-
#txn ⇒ Object
readonly
Returns the value of attribute txn.
Instance Method Summary collapse
- #add(txn) ⇒ Object
- #includes?(txn) ⇒ Boolean
-
#initialize(txn) ⇒ WriteLock
constructor
A new instance of WriteLock.
- #remove(txn) ⇒ Object
- #unlocked? ⇒ Boolean
Constructor Details
#initialize(txn) ⇒ WriteLock
Returns a new instance of WriteLock.
53 54 55 56 |
# File 'lib/spinoza/system/lock-manager.rb', line 53 def initialize txn @txn = txn @count = 1 end |
Instance Attribute Details
#count ⇒ Object (readonly)
Returns the value of attribute count.
51 52 53 |
# File 'lib/spinoza/system/lock-manager.rb', line 51 def count @count end |
#txn ⇒ Object (readonly)
Returns the value of attribute txn.
51 52 53 |
# File 'lib/spinoza/system/lock-manager.rb', line 51 def txn @txn end |
Instance Method Details
#add(txn) ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/spinoza/system/lock-manager.rb', line 66 def add txn if includes? txn @count += 1 else raise ConcurrencyError, "#{self} is not locked by #{txn}" end end |
#includes?(txn) ⇒ Boolean
62 63 64 |
# File 'lib/spinoza/system/lock-manager.rb', line 62 def includes? txn @txn == txn && @count > 0 end |
#remove(txn) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/spinoza/system/lock-manager.rb', line 74 def remove txn if includes? txn @count -= 1 @txn = nil if @count == 0 else raise ConcurrencyError, "#{self} is not locked by #{txn}" end end |
#unlocked? ⇒ Boolean
58 59 60 |
# File 'lib/spinoza/system/lock-manager.rb', line 58 def unlocked? @txn == nil end |