System.Threading.ReaderWriterLock.RecoverLock C# (CSharp) Method

RecoverLock() private method

Helper function that restores the lock to the original state indicated by parameters
private RecoverLock ( LockCookie &lockCookie, LockCookieFlags flags ) : void
lockCookie LockCookie
flags LockCookieFlags
return void
        private void RecoverLock(ref LockCookie lockCookie, LockCookieFlags flags)
        {
            // Contrary to the legacy code, this method does not use a finite timeout for recovering the previous lock state, as
            // a timeout would leave the lock in an inconsistent state. That possibility is not documented, but as documented,
            // the caller of the public entry method should expect that it does not return until the state is consistent.

            // Check if the thread was a writer
            if ((flags & LockCookieFlags.OwnedWriter) != 0)
            {
                // Acquire writer lock
                AcquireWriterLock(Timeout.Infinite);
                _writerLevel = lockCookie._writerLevel;
            }
            // Check if the thread was a reader
            else if ((flags & LockCookieFlags.OwnedReader) != 0)
            {
                AcquireReaderLock(Timeout.Infinite);
                ThreadLocalLockEntry threadLocalLockEntry = ThreadLocalLockEntry.GetCurrent(_lockID);
                Debug.Assert(threadLocalLockEntry != null);
                threadLocalLockEntry._readerLevel = lockCookie._readerLevel;
            }
        }