Esempio n. 1
0
        /// <summary>
        /// Acquires a writer lock.
        /// </summary>
        /// <param name="transactionId">A token used to identify the holder of the lock.</param>
        /// <param name="timeSpan">The time that the thread will wait for the lock.</param>
        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void AcquireWriterLock(global::System.Guid transactionId, global::System.TimeSpan timeSpan)
        {
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                this.writerWaiters = (this.writerWaiters + 1);
                if ((this.writer != transactionId))
                {
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index >= 0))
                    {
                        this._readers.RemoveAt(index);
                        if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
                        {
                            this._readersStackTrace.RemoveAt(index);
                        }
                    }
                    for (
                        ; ((this.writer != global::System.Guid.Empty) ||
                           (this._readers.Count != 0));
                        )
                    {
                        try
                        {
                            try
                            {
                                global::System.Threading.Monitor.Enter(this.writerRoot);
                                global::System.Threading.Monitor.Exit(this.rowRoot);
                                if (false == global::System.Threading.Monitor.Wait(this.writerRoot, timeSpan))
                                {
                                    try
                                    {
                                        EventLog.Information("AcquireWriterLock TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                                    }
                                    catch
                                    {
                                    }

                                    throw new FluidTrade.Core.Utilities.DeadlockException("AcquireWriterLock TIMEOUT", null);
                                }
                            }
                            finally
                            {
                                global::System.Threading.Monitor.Exit(this.writerRoot);
                            }
                        }
                        finally
                        {
                            global::System.Threading.Monitor.Enter(this.rowRoot);
                        }
                    }
                    this.writer = transactionId;
                }
            }
            finally
            {
                this.writerWaiters = (this.writerWaiters - 1);
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// Releases every lock held by this record.
 /// </summary>
 /// <param name="transactionId">A token used to identify the holder of the lock.</param>
 //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
 public virtual void ReleaseLock(global::System.Guid transactionId)
 {
     try
     {
         global::System.Threading.Monitor.Enter(this.rowRoot);
         int index = this._readers.BinarySearch(transactionId);
         if ((index >= 0))
         {
             this._readers.RemoveAt(index);
             if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
             {
                 this._readersStackTrace.RemoveAt(index);
             }
             if (((this._readers.Count == 0) &&
                  (this.writerWaiters != 0)))
             {
                 try
                 {
                     global::System.Threading.Monitor.Enter(this.writerRoot);
                     global::System.Threading.Monitor.Pulse(this.writerRoot);
                 }
                 finally
                 {
                     global::System.Threading.Monitor.Exit(this.writerRoot);
                 }
             }
         }
         if ((this.writer == transactionId))
         {
             this.writer = global::System.Guid.Empty;
             if ((this.readerWaiters > 0))
             {
                 global::System.Threading.Monitor.PulseAll(this.rowRoot);
             }
             else
             {
                 if ((this.writerWaiters > 0))
                 {
                     try
                     {
                         global::System.Threading.Monitor.Enter(this.writerRoot);
                         global::System.Threading.Monitor.Pulse(this.writerRoot);
                     }
                     finally
                     {
                         global::System.Threading.Monitor.Exit(this.writerRoot);
                     }
                 }
             }
         }
     }
     finally
     {
         global::System.Threading.Monitor.Exit(this.rowRoot);
     }
 }
Esempio n. 3
0
 private void InsertToReaderList(global::System.Guid transactionId, int index)
 {
     this._readers.Insert(((0 - index)
                           - 1), transactionId);
     if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
     {
         this._readersStackTrace.Insert(((0 - index)
                                         - 1), UnhandledExceptionHelper.GetStackString());
     }
 }
Esempio n. 4
0
 protected DataRowBase(global::System.Data.DataRowBuilder dataRowBuilder) :
     base(dataRowBuilder)
 {
     this._readers = new global::System.Collections.Generic.List <System.Guid>();
     if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
     {
         this._readersStackTrace = new System.Collections.Generic.List <string>();
     }
     this.rowRoot    = new object();
     this.writerRoot = new object();
     this.writer     = global::System.Guid.Empty;
 }
Esempio n. 5
0
        /// <summary>
        /// Releases the reader lock on this record.
        /// </summary>
        /// <param name="transactionId">A token used to hold locks.</param>
        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void ReleaseReaderLock(global::System.Guid transactionId)
        {
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                if (this.writer != transactionId)                //no-op if there is a writer lock
                {
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index < 0))
                    {
                        throw new global::System.ServiceModel.FaultException <FluidTrade.Core.SynchronizationLockFault>(new global::FluidTrade.Core.SynchronizationLockFault(this.Table.TableName));
                    }
                    this._readers.RemoveAt(index);
                    if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
                    {
                        this._readersStackTrace.RemoveAt(index);
                    }

                    if (((this._readers.Count == 0) &&
                         (this.writerWaiters != 0)))
                    {
                        try
                        {
                            global::System.Threading.Monitor.Enter(this.writerRoot);
                            global::System.Threading.Monitor.Pulse(this.writerRoot);
                        }
                        finally
                        {
                            global::System.Threading.Monitor.Exit(this.writerRoot);
                        }
                    }
                }
            }
            finally
            {
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
        }
Esempio n. 6
0
        /// <summary>
        /// Acquires a writer lock for this record.
        /// </summary>
        /// <param name="dataModelTransaction">The transaction context for this operation.</param>
        //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
        public virtual void AcquireWriterLock(IDataModelTransaction dataModelTransaction)
        {
            global::System.Guid transactionId = dataModelTransaction.TransactionId;
            try
            {
                global::System.Threading.Monitor.Enter(this.rowRoot);
                this.writerWaiters = (this.writerWaiters + 1);
                if ((this.writer != transactionId))
                {
                    int index = this._readers.BinarySearch(transactionId);
                    if ((index >= 0))
                    {
                        this._readers.RemoveAt(index);
                        if (EventLog.IsLoggingEnabledFor(EventLog.ErrorLogLevel.Verbose))
                        {
                            this._readersStackTrace.RemoveAt(index);
                        }
                    }
                    for (
                        ; ((this.writer != global::System.Guid.Empty) ||
                           (this._readers.Count != 0));
                        )
                    {
                        try
                        {
                            try
                            {
                                global::System.Threading.Monitor.Enter(this.writerRoot);
                                global::System.Threading.Monitor.Exit(this.rowRoot);
                                if (false == global::System.Threading.Monitor.Wait(this.writerRoot, this.LockTimeout))
                                {
                                    try
                                    {
                                        EventLog.Information("AcquireWriterLock TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false));
                                    }
                                    catch
                                    {
                                    }

                                    throw new FluidTrade.Core.Utilities.DeadlockException("AcquireWriterLock TIMEOUT", null);
                                }
                            }
                            finally
                            {
                                global::System.Threading.Monitor.Exit(this.writerRoot);
                            }
                        }
                        finally
                        {
                            global::System.Threading.Monitor.Enter(this.rowRoot);
                        }
                    }
                    this.writer = transactionId;
                }
            }
            finally
            {
                this.writerWaiters = (this.writerWaiters - 1);
                global::System.Threading.Monitor.Exit(this.rowRoot);
            }
            dataModelTransaction.AddLock(this);
            if ((this.RowState == global::System.Data.DataRowState.Detached))
            {
                throw new global::System.Exception("The " + this.GetType().FullName + " record was deleted after it was locked");
            }
        }