/// <summary> /// Implements the ResourceLock's WaitToWrite behavior. /// </summary> protected override void OnEnter(Boolean exclusive) { if (exclusive) { // Indicate that a writer wants to write: WP++ Interlocked.Add(ref m_LockState, c_1WritersPending); StressPause(); // OK to write if no readers are reading and // no writers are pending: RR=0, WP=don't care, WW=0 // Set the Writer is writing bit on. InterlockedEx.MaskedOr(ref m_LockState, c_lsOwnedByWriter, c_WritersPendingMask); } else { // OK to read if no writers are waiting: RR=don't care, WP=0, WW=0 // If we're good, add 1 to the RR InterlockedEx.MaskedAdd(ref m_LockState, c_1ReadersReading, c_ReadersReadingMask); } StressPause(); }