public LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode) { lock (this) { int count = 0; if ((accessType & AccessType.Read) != 0) { count += lockables.Length; } if ((accessType & AccessType.Write) != 0) { count += lockables.Length; } var handle = new LockHandle(count); if ((accessType & AccessType.Read) != 0) { AddToHandle(handle, lockables, AccessType.Read, mode); } if ((accessType & AccessType.Write) != 0) { AddToHandle(handle, lockables, AccessType.Write, mode); } return(handle); } }
public LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode) { lock (this) { var handle = new LockHandle(this); for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); if ((accessType & AccessType.Read) != 0) { handle.AddLock(queue.Lock(mode, AccessType.Read)); } if ((accessType & AccessType.Write) != 0) { handle.AddLock(queue.Lock(mode, AccessType.Write)); } } openHandles.Add(handle); return(handle); } }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { // Set up the local constants. int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); lock (this) { Lock @lock; LockingQueue queue; // Add Read and Write locks to cache and to the handle. for (int i = toWrite.Length - 1; i >= 0; --i) { var toWriteLock = toWrite[i]; queue = GetQueueFor(toWriteLock); // slightly confusing: this will add Lock to given table queue @lock = new Lock(queue, mode, AccessType.Write); @lock.Acquire(); handle.AddLock(@lock); } for (int i = toRead.Length - 1; i >= 0; --i) { var toReadLock = toRead[i]; queue = GetQueueFor(toReadLock); // slightly confusing: this will add Lock to given table queue @lock = new Lock(queue, mode, AccessType.Read); @lock.Acquire(); handle.AddLock(@lock); } } return handle; }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { lock (this) { int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); AddToHandle(handle, toWrite, AccessType.Write, mode); AddToHandle(handle, toRead, AccessType.Read, mode); return(handle); } }
public void Release(LockHandle handle) { lock (this) { if (openHandles != null) { var index = openHandles.IndexOf(handle); if (index >= 0) { openHandles.RemoveAt(index); } } handle.ReleaseLocks(); } }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) { return; } for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); handle.AddLock(queue.NewLock(mode, accessType)); } }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) { return; } for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); // slightly confusing: this will add Lock to given table queue var @lock = new Lock(queue, mode, accessType); @lock.Acquire(); handle.AddLock(@lock); } }
public LockHandle Lock(ILockable[] lockables, AccessType accessType, LockingMode mode) { lock (this) { int count = 0; if ((accessType & AccessType.Read) != 0) count += lockables.Length; if ((accessType & AccessType.Write) != 0) count += lockables.Length; var handle = new LockHandle(count); if ((accessType & AccessType.Read) != 0) AddToHandle(handle, lockables, AccessType.Read, mode); if ((accessType & AccessType.Write) != 0) AddToHandle(handle, lockables, AccessType.Write, mode); return handle; } }
public void Unlock(LockHandle handle) { lock (this) { handle.Release(); } }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) return; for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); handle.AddLock(queue.NewLock(mode, accessType)); } }
public void Unlock(LockHandle handle) { lock (this) { if (openHandles != null) { var index = openHandles.IndexOf(handle); if (index >= 0) openHandles.RemoveAt(index); } handle.Release(); } }
public LockHandle Lock(ILockable[] toWrite, ILockable[] toRead, LockingMode mode) { lock (this) { int lockCount = toRead.Length + toWrite.Length; LockHandle handle = new LockHandle(lockCount); AddToHandle(handle, toWrite, AccessType.Write, mode); AddToHandle(handle, toRead, AccessType.Read, mode); return handle; } }
private void AddToHandle(LockHandle handle, ILockable[] lockables, AccessType accessType, LockingMode mode) { if (lockables == null) return; for (int i = lockables.Length - 1; i >= 0; --i) { var lockable = lockables[i]; var queue = GetQueueFor(lockable); // slightly confusing: this will add Lock to given table queue var @lock = new Lock(queue, mode, accessType); @lock.Acquire(); handle.AddLock(@lock); } }