public void TestDebugFactoryRecursiveOptions() { DebugLockFactory <SimpleReadWriteLocking> factory = new DebugLockFactory <SimpleReadWriteLocking>( false, 0, 1, false, 1); using (ILockStrategy lck = factory.Create()) { using (lck.Write()) using (lck.Write()) //second lock, allow recurse 1 time as per constructor { try { using (lck.Write()) { Assert.Fail(); } } catch (Exception ex) { Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock } } using (lck.Read()) using (lck.Read()) //second lock, allow recurse 1 time as per constructor { try { using (lck.Read()) { Assert.Fail(); } } catch (Exception ex) { Assert.IsTrue(ex is DebugAssertionFailedException);//nesting prohibited by debug lock } } } }
public override void UpdateNode(NodePin node) { if (node.IsDeleted) { using (_lock.Write(base.Options.LockTimeout)) _list.Remove(node.Handle.StoreHandle); } }
public void Enqueue(string value) { using (_writeLock.Write()) { _write.WriteLine(value); _write.Flush(); } }
public void TestWriteRecursion() { ILockStrategy l = LockFactory.Create(); using (l.Write()) using (l.Write()) using (l.Write()) { } }
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); } }
protected Node CreateRoot(NodeHandle rootHandle) { NodeHandle hChild; using (NodeTransaction t = BeginTransaction()) { using (NodePin child = t.Create(LockType.Insert, true)) { hChild = child.Handle; t.Commit(); } } object refobj; RootNode rootNode = new RootNode(rootHandle.StoreHandle); ILockStrategy lck = CreateLock(rootHandle, out refobj); using (lck.Write(Options.LockTimeout)) { using (NodePin rootPin = new NodePin(rootHandle, lck, LockType.Insert, LockType.Insert, refobj, rootNode, null)) using (NodeTransaction t = BeginTransaction()) { rootNode = (RootNode)t.BeginUpdate(rootPin); rootNode.ReplaceChild(0, null, hChild); t.Commit(); } } return(rootNode); }
void OnChanged() { if (_options.TransactionLogLimit > 0 && _options.LogFile != null) { if (_options.LogFile.Size > _options.TransactionLogLimit) { using (_selfLock.Write(LockTimeout)) { if (_options.LogFile.Size > _options.TransactionLogLimit) { CommitChanges(false); } } } } }
/// <summary> /// Locks the collection and replaces the underlying storage dictionary. /// </summary> public IList <T> ReplaceStorage(IList <T> newStorage) { using (_lock.Write()) { IList <T> storage = _store; _store = Check.NotNull(newStorage); return(storage); } }
CacheEntry GetCache(NodeHandle handle, bool isNew) { Utils.WeakReference <CacheEntry> weakRef; CacheEntry entry = null; if (!isNew) { if (handle.TryGetCache(out weakRef) && weakRef != null && weakRef.TryGetTarget(out entry)) { return(entry); } using (_cacheLock.Read(base.Options.LockTimeout)) { if (_cache.TryGetValue(handle, out weakRef)) { if (!weakRef.TryGetTarget(out entry)) { using (new SafeLock <DeadlockException>(weakRef)) { if (!weakRef.TryGetTarget(out entry)) { weakRef.Target = entry = new CacheEntry(this, handle); } handle.SetCacheEntry(weakRef); } } } } } if (entry == null) { using (_cacheLock.Write(base.Options.LockTimeout)) { if (!_cache.TryGetValue(handle, out weakRef)) { _cache.Add(handle, weakRef = new Utils.WeakReference <CacheEntry>(entry = new CacheEntry(this, handle))); handle.SetCacheEntry(weakRef); } else { if (!weakRef.TryGetTarget(out entry)) { using (new SafeLock <DeadlockException>(weakRef)) { if (!weakRef.TryGetTarget(out entry)) { weakRef.Target = entry = new CacheEntry(this, handle); } handle.SetCacheEntry(weakRef); } } } } } Assert(entry != null, "Cache entry is null"); _keepAlive.Add(entry); return(entry); }
public void TestYouCanDisposeWriteLock() { using (ILockStrategy l = LockFactory.Create()) using (IDisposable w = l.Write()) { w.Dispose();//since the using statement has the same boxed pointer to w, we are allowed to dispose } }
public bool TryDequeue(out string value) { using (_writeLock.Read()) using (_readLock.Write()) { value = _read.ReadLine(); } return(value != null); }
public virtual void TestWriteToReadRecursion() { using (ILockStrategy l = LockFactory.Create()) { using (l.Write()) using (l.Read()) using (l.Read()) { } } }
public void NoWriteIncrement() { using (ILockStrategy l = LockFactory.Create()) { Assert.AreEqual(0, l.WriteVersion); using (l.Write()) Assert.AreEqual(0, l.WriteVersion); Assert.AreEqual(0, l.WriteVersion); } }
public void TestReadThenWrite() { using (ILockStrategy l = LockFactory.Create()) { using (l.Read()) { } using (l.Write()) { } } }
public void TestWriteThenReadWithTimeout() { using (ILockStrategy l = LockFactory.Create()) { using (l.Write(0)) { } using (l.Read(0)) { } } }
public void Rollback() { ITransactable tstore = _store as ITransactable; if (tstore != null) { using (_lock.Write()) { _ordered.Clear(); _cache.Clear(); tstore.Rollback(); } } }
public void TestWrite() { using (ILockStrategy l = LockFactory.Create()) using (l.Write()) { } }
public void TestThreadedWriteTimeout() { using (ILockStrategy l = LockFactory.Create()) using (new ThreadedWriter(l)) using (l.Write(0)) { } }
protected virtual IDisposable Lock() { return(_lck.Write(100)); }
/// <summary> /// Locks the collection and replaces the underlying storage dictionary. /// </summary> public IDictionary <TKey, TValue> ReplaceStorage(IDictionary <TKey, TValue> newStorage) { using (_lock.Write()) { IDictionary <TKey, TValue> storage = _store; _store = Check.NotNull(newStorage); return(storage); } }