public void TestWriterBlocksReader() { using (ILockStrategy l = LockFactory.Create()) { Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); using (new ThreadedWriter(l)) Assert.IsFalse(l.TryRead(0)); Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); } }
public override void TestWriteCounter() { using (ILockStrategy l = LockFactory.Create()) { Assert.AreEqual(0, l.WriteVersion); Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); Assert.AreEqual(0, l.WriteVersion); Assert.IsTrue(l.TryWrite(0)); Assert.AreEqual(0, l.WriteVersion); l.ReleaseWrite(); Assert.AreEqual(0, l.WriteVersion); using (l.Write()) { Assert.AreEqual(0, l.WriteVersion); Assert.IsTrue(l.TryWrite(0)); // Once a nested write lock is acquired the real lock is obtained. Assert.AreEqual(1, l.WriteVersion); l.ReleaseWrite(); Assert.AreEqual(1, l.WriteVersion); } Assert.IsTrue(l.TryWrite(0)); l.ReleaseWrite(); Assert.AreEqual(1, l.WriteVersion); } }
public void TestTryRead() { using (ILockStrategy l = LockFactory.Create()) { Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); } }
public void Dispose() { if (_hasLock) { _lock.ReleaseRead(); } _hasLock = false; }
public virtual void TestReaderAllowsReader() { using (ILockStrategy l = LockFactory.Create()) { using (new ThreadedReader(l)) Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); } }
public void Dispose() { if (_lockHeld == LockType.Read) { _lock.ReleaseRead(); } else if (_lockHeld != NoLock) { _lock.ReleaseWrite(); } _lockHeld = NoLock; //if (_temp != null) // _temp.Invalidate(); _temp = null; }
public virtual void TestWriteCounter() { ILockStrategy l = LockFactory.Create(); int count = l.WriteVersion; Assert.IsTrue(l.TryRead(0)); l.ReleaseRead(); Assert.AreEqual(count, l.WriteVersion); Assert.IsTrue(l.TryWrite(0)); l.ReleaseWrite(); Assert.AreNotEqual(count, l.WriteVersion); count = l.WriteVersion; Assert.IsTrue(l.TryWrite(0)); l.ReleaseWrite(); Assert.AreNotEqual(count, l.WriteVersion); }
public void ReleaseRead() { _lock.ReleaseRead(); AddThreadCount(-1, 0); }
public void ReleaseRead() { _lock.ReleaseRead(); Interlocked.Decrement(ref _factory.CurrentReaderCount); }
public void TestExcessiveReleaseRead() { using (ILockStrategy l = LockFactory.Create()) l.ReleaseRead(); }