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);
            }
        }
Ejemplo n.º 2
0
        public void TestThreadedTryWrite()
        {
            using (ILockStrategy l = LockFactory.Create())
            {
                Assert.IsTrue(l.TryWrite(0));
                l.ReleaseWrite();

                using (new ThreadedWriter(l))
                    Assert.IsFalse(l.TryWrite(0));

                Assert.IsTrue(l.TryWrite(0));
                l.ReleaseWrite();
            }
        }
Ejemplo n.º 3
0
 public void TestTryWrite()
 {
     using (ILockStrategy l = LockFactory.Create())
     {
         Assert.IsTrue(l.TryWrite(0));
         l.ReleaseWrite();
     }
 }
 public void Dispose()
 {
     if (_hasLock)
     {
         _lock.ReleaseWrite();
     }
     _hasLock = false;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Closes the storage and clears memory used by the instance
 /// </summary>
 public void Dispose()
 {
     if (_disposed)
     {
         return;
     }
     try
     {
         bool locked = false;
         try
         {
             if (!IsReadOnly)
             {
                 locked = _selfLock.TryWrite(Math.Max(1000, LockTimeout));
                 if (locked)
                 {
                     CommitChanges(false);
                 }
             }
             _storage.Dispose();
         }
         finally
         {
             try
             {
                 if (_options.LogFile != null)
                 {
                     _options.LogFile.Dispose();
                 }
             }
             finally
             {
                 if (locked)
                 {
                     _selfLock.ReleaseWrite();
                 }
                 //Do not dispose, this may be a shared lock:
                 //_selfLock.Dispose();
             }
         }
     }
     finally
     {
         _disposed = true;
     }
 }
Ejemplo n.º 6
0
        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 Dispose()
            {
                if (_lockHeld == LockType.Read)
                {
                    _lock.ReleaseRead();
                }
                else if (_lockHeld != NoLock)
                {
                    _lock.ReleaseWrite();
                }

                _lockHeld = NoLock;
                //if (_temp != null)
                //    _temp.Invalidate();
                _temp = null;
            }
Ejemplo n.º 8
0
 public void ReleaseWrite()
 {
     _lock.ReleaseWrite();
     AddThreadCount(0, -1);
 }
Ejemplo n.º 9
0
 public void ReleaseWrite()
 {
     _lock.ReleaseWrite();
     Interlocked.Decrement(ref _factory.CurrentWriterCount);
 }
 public void TestExcessiveReleaseWrite()
 {
     using (ILockStrategy l = LockFactory.Create())
         l.ReleaseWrite();
 }