/// <summary> /// Releases all the resources used by the <see cref="TransactionalFileStructure"/> object. /// </summary> public void Dispose() { if (!m_disposed) { try { if (m_currentTransaction != null) { m_currentTransaction.Dispose(); m_currentTransaction = null; } if (m_diskIo != null) { m_diskIo.Dispose(); m_diskIo = null; } } finally { GC.SuppressFinalize(this); m_disposed = true; // Prevent duplicate dispose. } } }
/// <summary> /// This will start a transactional edit on the file. /// </summary> /// <returns></returns> public TransactionalEdit BeginEdit() { if (m_diskIo.IsReadOnly) { throw new Exception("File has been opened in readonly mode"); } TransactionalEdit transaction = new TransactionalEdit(m_diskIo, OnTransactionRolledBack, OnTransactionCommitted); Interlocked.CompareExchange(ref m_currentTransaction, transaction, null); if (m_currentTransaction != transaction) { throw new Exception("Only one edit transaction can exist at one time."); } return(m_currentTransaction); }
private void OnTransactionRolledBack() { m_currentTransaction = null; }
private void OnTransactionCommitted() { m_currentReadTransaction = new ReadSnapshot(m_diskIo); Thread.MemoryBarrier(); m_currentTransaction = null; }