Exemple #1
0
        public Page EnterLatch(BufferEntry buffer, LatchFlags flags)
        {
            if (LatchLocks.TryGetValue(buffer.Position, out var latchLock))
            {
                if (flags != latchLock.Flags)
                {
                    throw new InvalidOperationException($"has hold a {flags} lactch of the buffer:{buffer.Position}!");
                }

                return(buffer.Page);
            }

            switch (flags)
            {
            case LatchFlags.Read:
                LatchLocks[buffer.Position] = buffer.Latch.EnterReadScope();
                break;

            case LatchFlags.RWRead:
                LatchLocks[buffer.Position] = buffer.Latch.EnterReadWriteScope();
                break;

            case LatchFlags.Write:
                LatchLocks[buffer.Position] = buffer.Latch.EnterWriteScope();
                break;
            }

            return(buffer.Page);
        }
Exemple #2
0
        public bool CheckLatch(BufferEntry buffer, LatchFlags flags)
        {
            if (!LatchLocks.TryGetValue(buffer.Position, out var latch))
            {
                return(false);
            }

            switch (flags)
            {
            case LatchFlags.Write:
                return(latch.Flags == LatchFlags.Write || latch.Flags == LatchFlags.RWWrite);

            default:
                return(true);
            }
        }
Exemple #3
0
        public Page EnterLatch(PagePosition page, LatchFlags flags)
        {
            if (LatchLocks.TryGetValue(page, out var latchLock))
            {
                if (flags != latchLock.Flags)
                {
                    throw new InvalidOperationException($"has hold a {flags} lactch of the buffer:{page}!");
                }

                return((latchLock.Latch.Target as BufferEntry)?.Page);
            }

            var buffer = Buffers.GetEntry(page);

            if (buffer == null)
            {
                throw new NullReferenceException(nameof(buffer));
            }

            switch (flags)
            {
            case LatchFlags.Read:
                LatchLocks[page] = buffer.Latch.EnterReadScope();
                break;

            case LatchFlags.Write:
                LatchLocks[page] = buffer.Latch.EnterWriteScope();
                break;

            case LatchFlags.RWRead:
                LatchLocks[page] = buffer.Latch.EnterReadWriteScope();
                break;
            }

            return(buffer.Page);
        }