DeveelDB  20151217
complete SQL database system, primarly developed for .NET/Mono frameworks
Public Member Functions | Package Functions | Properties | Private Attributes | List of all members
Deveel.Data.Transactions.LockingQueue Class Reference

Public Member Functions

void Acquire (Lock @lock)
 
void Release (Lock @lock)
 

Package Functions

 LockingQueue (ILockable lockable)
 
void CheckAccess (Lock @lock)
 

Properties

ILockable Lockable [get, private set]
 
bool IsEmpty [get]
 

Private Attributes

readonly List< Locklocks
 

Detailed Description

Definition at line 23 of file LockingQueue.cs.

Constructor & Destructor Documentation

Deveel.Data.Transactions.LockingQueue.LockingQueue ( ILockable  lockable)
inlinepackage

Definition at line 26 of file LockingQueue.cs.

26  {
27  Lockable = lockable;
28  locks = new List<Lock>();
29  }

Member Function Documentation

void Deveel.Data.Transactions.LockingQueue.Acquire ( Lock lock)
inline

Definition at line 41 of file LockingQueue.cs.

41  {
42  lock (this) {
43  locks.Add(@lock);
44  }
45  }
void Deveel.Data.Transactions.LockingQueue.CheckAccess ( Lock lock)
inlinepackage

Definition at line 55 of file LockingQueue.cs.

55  {
56  lock (this) {
57  // Error checking. The queue must contain the Lock.
58  if (!locks.Contains(@lock))
59  throw new InvalidOperationException("Queue does not contain the given Lock");
60 
61  // If 'READ'
62  bool blocked;
63  int index;
64  if (@lock.AccessType == AccessType.Read) {
65  do {
66  blocked = false;
67 
68  index = locks.IndexOf(@lock);
69 
70  int i;
71  for (i = index - 1; i >= 0 && !blocked; --i) {
72  var testLock = locks[i];
73  if (testLock.AccessType == AccessType.Write)
74  blocked = true;
75  }
76 
77  if (blocked) {
78  Monitor.Wait(this);
79  }
80  } while (blocked);
81  } else {
82  do {
83  blocked = false;
84 
85  index = locks.IndexOf(@lock);
86 
87  if (index != 0) {
88  blocked = true;
89 
90  Monitor.Wait(this);
91  }
92 
93  } while (blocked);
94  }
95 
96  // Notify the Lock table that we've got a lock on it.
97  // TODO: Lock.Table.LockAcquired(Lock);
98  }
99  }
void Deveel.Data.Transactions.LockingQueue.Release ( Lock lock)
inline

Definition at line 47 of file LockingQueue.cs.

47  {
48  lock (this) {
49  locks.Remove(@lock);
50  Lockable.Released(@lock);
51  Monitor.PulseAll(this);
52  }
53  }

Member Data Documentation

readonly List<Lock> Deveel.Data.Transactions.LockingQueue.locks
private

Definition at line 24 of file LockingQueue.cs.

Property Documentation

bool Deveel.Data.Transactions.LockingQueue.IsEmpty
get

Definition at line 33 of file LockingQueue.cs.

ILockable Deveel.Data.Transactions.LockingQueue.Lockable
getprivate set

Definition at line 31 of file LockingQueue.cs.


The documentation for this class was generated from the following file: