18 using System.Collections.Generic;
20 namespace Deveel.Data.Transactions {
22 private readonly Dictionary<object, LockingQueue> queuesMap =
new Dictionary<object, LockingQueue>();
31 if (lockables == null)
34 for (
int i = lockables.Length - 1; i >= 0; --i) {
35 var lockable = lockables[i];
36 var queue = GetQueueFor(lockable);
39 var @lock =
new Lock(queue, mode, accessType);
49 count += lockables.Length;
51 count += lockables.Length;
56 AddToHandle(handle, lockables,
AccessType.Read, mode);
59 AddToHandle(handle, lockables,
AccessType.Write, mode);
66 return Lock(
new[] {lockable}, accessType, mode);
87 int lockCount = toRead.Length + toWrite.Length;
90 AddToHandle(handle, toWrite,
AccessType.Write, mode);
91 AddToHandle(handle, toRead,
AccessType.Read, mode);
100 if (!queuesMap.TryGetValue(lockable.
RefId, out queue)) {
102 queuesMap[lockable.
RefId] = queue;
123 if (!queuesMap.TryGetValue(lockable.
RefId, out queue))
LockHandle LockRead(ILockable lockable, LockingMode mode)
void Unlock(LockHandle handle)
LockingQueue GetQueueFor(ILockable lockable)
LockingMode
The mode applied to a lock over a resource during a transaction.
LockHandle Lock(ILockable lockable, AccessType accessType, LockingMode mode)
LockHandle LockRead(ILockable[] lockables, LockingMode mode)
The default implementation of a database in a system.
bool IsLocked(ILockable lockable)
The representation of a single database in the system.
Locker(IDatabase database)
LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode)
LockHandle LockWrite(ILockable lockable, LockingMode mode)
LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode)
LockHandle LockWrite(ILockable[] lockables, LockingMode mode)
void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode)