예제 #1
0
        /// <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.
                }
            }
        }
예제 #2
0
        /// <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);
        }
예제 #3
0
 private void OnTransactionRolledBack()
 {
     m_currentTransaction = null;
 }
예제 #4
0
 private void OnTransactionCommitted()
 {
     m_currentReadTransaction = new ReadSnapshot(m_diskIo);
     Thread.MemoryBarrier();
     m_currentTransaction = null;
 }