Class: Spinoza::LockManager::WriteLock

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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

#countObject (readonly)

Returns the value of attribute count.



51
52
53
# File 'lib/spinoza/system/lock-manager.rb', line 51

def count
  @count
end

#txnObject (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

Returns:

  • (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

Returns:

  • (Boolean)


58
59
60
# File 'lib/spinoza/system/lock-manager.rb', line 58

def unlocked?
  @txn == nil
end