Ejemplo 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;
        }
Ejemplo n.º 2
0
        internal Lock Lock(LockingMode mode, AccessType accessType)
        {
            lock (this) {
                var @lock = new Lock(this, mode, accessType);
                Locked.Locked(@lock);
                locks.Add(@lock);
                @lock.Acquire();

                return(@lock);
            }
        }
Ejemplo n.º 3
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);
            }
        }
Ejemplo n.º 4
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);
            }
        }