Наследование: IDisposable
Пример #1
0
        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);
            }
        }
Пример #2
0
        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);
            }
        }
Пример #3
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;
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        public void Release(LockHandle handle)
        {
            lock (this) {
                if (openHandles != null)
                {
                    var index = openHandles.IndexOf(handle);
                    if (index >= 0)
                    {
                        openHandles.RemoveAt(index);
                    }
                }

                handle.ReleaseLocks();
            }
        }
Пример #6
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);

                handle.AddLock(queue.NewLock(mode, accessType));
            }
        }
Пример #7
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);
            }
        }
Пример #8
0
        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;
            }
        }
Пример #9
0
 public void Unlock(LockHandle handle)
 {
     lock (this) {
         handle.Release();
     }
 }
Пример #10
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);

                handle.AddLock(queue.NewLock(mode, accessType));
            }
        }
Пример #11
0
        public void Unlock(LockHandle handle)
        {
            lock (this) {
                if (openHandles != null) {
                    var index = openHandles.IndexOf(handle);
                    if (index >= 0)
                        openHandles.RemoveAt(index);
                }

                handle.Release();
            }
        }
Пример #12
0
 public void Unlock(LockHandle handle)
 {
     lock (this) {
         handle.Release();
     }
 }
Пример #13
0
        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;
            }
        }
Пример #14
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);
            }
        }