public void Write(Action <Stream> readWriteAction) { lock (this) { if (disposed) { throw new ObjectDisposedException("Cannot access persistent source after it was disposed"); } bool success = false; try { CurrentStates = new List <PersistentDictionaryState>( globalStates.Select(x => new PersistentDictionaryState(x.Comparer) { KeyToFilePositionInFiles = x.KeyToFilePositionInFiles, SecondaryIndicesState = x.SecondaryIndicesState.ToList() })); readWriteAction(Log); success = true; } finally { if (success) { pool.Clear(); globalStates = CurrentStates; } CurrentStates = null; } } }
public void Write(Action <Stream> readWriteAction) { lock (this) { if (disposed) { throw new ObjectDisposedException("Cannot access persistent source after it was disposed"); } try { CurrentStates = new List <PersistentDictionaryState>( globalStates.Select(x => new PersistentDictionaryState(x.Comparer) { KeyToFilePositionInFiles = x.KeyToFilePositionInFiles, SecondaryIndicesState = x.SecondaryIndicesState })); readWriteAction(Log); } finally { pool.Clear(); Interlocked.Exchange(ref globalStates, CurrentStates); CurrentStates = null; } } }
public void Write(Action <Stream> readWriteAction) { lock (this) { try { currentStates.Value = new List <PersistentDictionaryState>( globalStates.Select(x => new PersistentDictionaryState(x.Comparer) { KeyToFilePositionInFiles = x.KeyToFilePositionInFiles, SecondaryIndicesState = x.SecondaryIndicesState })); readWriteAction(Log); } finally { pool.Clear(); Interlocked.Exchange(ref globalStates, currentStates.Value); currentStates.Value = null; } } }