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

Public Member Functions

 Locker (IDatabase database)
 
LockHandle Lock (ILockable[] lockables, AccessType accessType, LockingMode mode)
 
LockHandle Lock (ILockable lockable, AccessType accessType, LockingMode mode)
 
LockHandle LockRead (ILockable lockable, LockingMode mode)
 
LockHandle LockRead (ILockable[] lockables, LockingMode mode)
 
LockHandle LockWrite (ILockable lockable, LockingMode mode)
 
LockHandle LockWrite (ILockable[] lockables, LockingMode mode)
 
LockHandle Lock (ILockable[] toWrite, ILockable[] toRead, LockingMode mode)
 
void Unlock (LockHandle handle)
 
void Reset ()
 
bool IsLocked (ILockable lockable)
 

Properties

IDatabase Database [get, private set]
 

Private Member Functions

void AddToHandle (LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode)
 
LockingQueue GetQueueFor (ILockable lockable)
 

Private Attributes

readonly Dictionary< object, LockingQueuequeuesMap = new Dictionary<object, LockingQueue>()
 

Detailed Description

Definition at line 21 of file Locker.cs.

Constructor & Destructor Documentation

Deveel.Data.Transactions.Locker.Locker ( IDatabase  database)
inline

Definition at line 24 of file Locker.cs.

24  {
25  Database = database;
26  }

Member Function Documentation

void Deveel.Data.Transactions.Locker.AddToHandle ( LockHandle  handle,
ILockable[]  lockables,
AccessType  accessType,
LockingMode  mode 
)
inlineprivate

Definition at line 30 of file Locker.cs.

30  {
31  if (lockables == null)
32  return;
33 
34  for (int i = lockables.Length - 1; i >= 0; --i) {
35  var lockable = lockables[i];
36  var queue = GetQueueFor(lockable);
37 
38  // slightly confusing: this will add Lock to given table queue
39  var @lock = new Lock(queue, mode, accessType);
40  @lock.Acquire();
41  handle.AddLock(@lock);
42  }
43  }
LockingQueue GetQueueFor(ILockable lockable)
Definition: Locker.cs:97
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
LockingQueue Deveel.Data.Transactions.Locker.GetQueueFor ( ILockable  lockable)
inlineprivate

Definition at line 97 of file Locker.cs.

97  {
98  LockingQueue queue;
99 
100  if (!queuesMap.TryGetValue(lockable.RefId, out queue)) {
101  queue = new LockingQueue(lockable);
102  queuesMap[lockable.RefId] = queue;
103  }
104 
105  return queue;
106  }
readonly Dictionary< object, LockingQueue > queuesMap
Definition: Locker.cs:22
bool Deveel.Data.Transactions.Locker.IsLocked ( ILockable  lockable)
inline

Definition at line 120 of file Locker.cs.

120  {
121  lock (this) {
122  LockingQueue queue;
123  if (!queuesMap.TryGetValue(lockable.RefId, out queue))
124  return false;
125 
126  return !queue.IsEmpty;
127  }
128  }
readonly Dictionary< object, LockingQueue > queuesMap
Definition: Locker.cs:22
LockHandle Deveel.Data.Transactions.Locker.Lock ( ILockable[]  lockables,
AccessType  accessType,
LockingMode  mode 
)
inline

Definition at line 45 of file Locker.cs.

45  {
46  lock (this) {
47  int count = 0;
48  if ((accessType & AccessType.Read) != 0)
49  count += lockables.Length;
50  if ((accessType & AccessType.Write) != 0)
51  count += lockables.Length;
52 
53  var handle = new LockHandle(count);
54 
55  if ((accessType & AccessType.Read) != 0)
56  AddToHandle(handle, lockables, AccessType.Read, mode);
57 
58  if ((accessType & AccessType.Write) != 0)
59  AddToHandle(handle, lockables, AccessType.Write, mode);
60 
61  return handle;
62  }
63  }
void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:30
LockHandle Deveel.Data.Transactions.Locker.Lock ( ILockable  lockable,
AccessType  accessType,
LockingMode  mode 
)
inline

Definition at line 65 of file Locker.cs.

65  {
66  return Lock(new[] {lockable}, accessType, mode);
67  }
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
LockHandle Deveel.Data.Transactions.Locker.Lock ( ILockable[]  toWrite,
ILockable[]  toRead,
LockingMode  mode 
)
inline

Definition at line 85 of file Locker.cs.

85  {
86  lock (this) {
87  int lockCount = toRead.Length + toWrite.Length;
88  LockHandle handle = new LockHandle(lockCount);
89 
90  AddToHandle(handle, toWrite, AccessType.Write, mode);
91  AddToHandle(handle, toRead, AccessType.Read, mode);
92 
93  return handle;
94  }
95  }
void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:30
LockHandle Deveel.Data.Transactions.Locker.LockRead ( ILockable  lockable,
LockingMode  mode 
)
inline

Definition at line 69 of file Locker.cs.

69  {
70  return Lock(lockable, AccessType.Read, mode);
71  }
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
LockHandle Deveel.Data.Transactions.Locker.LockRead ( ILockable[]  lockables,
LockingMode  mode 
)
inline

Definition at line 73 of file Locker.cs.

73  {
74  return Lock(lockables, AccessType.Read, mode);
75  }
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
LockHandle Deveel.Data.Transactions.Locker.LockWrite ( ILockable  lockable,
LockingMode  mode 
)
inline

Definition at line 77 of file Locker.cs.

77  {
78  return Lock(lockable, AccessType.Write, mode);
79  }
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
LockHandle Deveel.Data.Transactions.Locker.LockWrite ( ILockable[]  lockables,
LockingMode  mode 
)
inline

Definition at line 81 of file Locker.cs.

81  {
82  return Lock(lockables, AccessType.Write, mode);
83  }
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
Definition: Locker.cs:45
void Deveel.Data.Transactions.Locker.Reset ( )
inline

Definition at line 114 of file Locker.cs.

114  {
115  lock (this) {
116  queuesMap.Clear();
117  }
118  }
readonly Dictionary< object, LockingQueue > queuesMap
Definition: Locker.cs:22
void Deveel.Data.Transactions.Locker.Unlock ( LockHandle  handle)
inline

Definition at line 108 of file Locker.cs.

108  {
109  lock (this) {
110  handle.Release();
111  }
112  }

Member Data Documentation

readonly Dictionary<object, LockingQueue> Deveel.Data.Transactions.Locker.queuesMap = new Dictionary<object, LockingQueue>()
private

Definition at line 22 of file Locker.cs.

Property Documentation

IDatabase Deveel.Data.Transactions.Locker.Database
getprivate set

Definition at line 28 of file Locker.cs.


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