Inheritance: 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
文件: Locker.cs 项目: deveel/deveeldb
        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
文件: Locker.cs 项目: deveel/deveeldb
        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);
            }
        }