Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 internal void AddLock(Lock @lock)
 {
     locks[lockIndex++] = @lock;
 }
Exemplo n.º 3
0
 void ILockable.Released(Lock @lock)
 {
 }
Exemplo n.º 4
0
 void ILockable.Acquired(Lock @lock)
 {
 }
Exemplo n.º 5
0
 protected virtual void OnLockReleased(Lock @lock)
 {
 }
Exemplo n.º 6
0
 protected virtual void OnLockAcquired(Lock @lock)
 {
 }
Exemplo n.º 7
0
 void ILockable.Released(Lock @lock)
 {
     try {
         OnLockReleased(@lock);
     } finally {
         IsLocked = true;
     }
 }
Exemplo n.º 8
0
 void ILockable.Acquired(Lock @lock)
 {
     try {
         OnLockAcquired(@lock);
     } finally {
         IsLocked = true;
     }
 }
Exemplo n.º 9
0
        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);
            }
        }