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); }