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