Esempio n. 1
0
        public void Unlock(TransactionHead transaction, bool unlockAll)
        {
            // All page locking is done by the root of the transaction heirachy. Locks are
            // only released when the outermost transaction completes
            transaction = transaction.Root;

            if (transaction != _lockingTransaction)
            {
                throw new FileLayerException("You cannot unlock a page that you do not have locked");
            }

            if (unlockAll)
            {
                _lockCount = 0;
            }
            else
            {
                _lockCount--;
            }

            if (_lockCount == 0)
            {
                _lockingTransaction = null;
                _unlockEvent.Set();
            }
        }
        public TransactionHead BeginTransaction(ITransaction transaction)
        {
            TransactionHead parentHead = null;

            if (transaction.ParentTransactionId.HasValue)
            {
                lock (_transactions)
                {
                    if (!_transactions.TryGetValue(transaction.ParentTransactionId.Value, out parentHead))
                    {
                        throw new FileLayerException("You can not start a child transaction when the parent transaction is not active");
                    }
                }
            }

            var transactionHead = new TransactionHead(transaction, parentHead, _pagePool);

            lock (_transactions) _transactions.Add(transaction.TransactionId, transactionHead);
            return(transactionHead);
        }
Esempio n. 3
0
        public void Lock(TransactionHead transaction)
        {
            // All page locking is done by the root of the transaction heirachy. Locks are
            // only released when the outermost transaction completes
            transaction = transaction.Root;

            // TODO: If there are transactions with modified versions of this
            //       page then we should wait for these transactions to complete
            //       and prevent any new write operations to the page

            while (true)
            {
                lock (Versions)
                {
                    if (_unlockEvent == null)
                    {
                        _unlockEvent = new ManualResetEventSlim(false);
                    }

                    if (_lockingTransaction == null)
                    {
                        _lockingTransaction = transaction;
                        _lockCount          = 1;
                        _unlockEvent.Reset();
                        return;
                    }
                    else if (_lockingTransaction == transaction)
                    {
                        _lockCount++;
                        return;
                    }
                }

                _unlockEvent.Wait();
            }
        }
Esempio n. 4
0
 public TransactionHead(ITransaction transaction, TransactionHead parent, IPagePool pagePool)
 {
     _pagePool   = pagePool;
     Transaction = transaction;
     Parent      = parent;
 }
Esempio n. 5
0
 /// <summary>
 /// Decrements the count of active transactions
 /// </summary>
 public bool TransactionEnded(TransactionHead transaction)
 {
     return(Interlocked.Decrement(ref _transactionCount) == 0);
 }
Esempio n. 6
0
 /// <summary>
 /// Increments the count of active transactions
 /// </summary>
 public void TransactionStarted(TransactionHead transaction)
 {
     Interlocked.Increment(ref _transactionCount);
 }