public virtual void AcquireWriterLock(IDataModelTransaction dataModelTransaction) { // This is a helper method and really just combines three frequently used operations to make the server-side code cleaner to read. this.AcquireWriterLock(dataModelTransaction.TransactionId, this.LockTimeout); dataModelTransaction.AddLock(this); // This will insure that we haven't attempted to lock a deleted row. This is a helper function to make the server-side transactions easier to write // and, thus, there's the potential to make mistakes that the generated data model would not make. if (this.RowState == DataRowState.Detached) { throw new LockException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.DeletedAfterLockedError, this.GetType())); } }
public virtual void AcquireReaderLock(IDataModelTransaction dataModelTransaction) { // Use the internal method to acquire the read lock. this.AcquireReaderLock(dataModelTransaction.TransactionId, this.LockTimeout); // This can now be added to the list of rows locked by the transaction. dataModelTransaction.AddLock(this); // This will insure that we haven't attempted to lock a deleted row. This is a helper function to make the server-side transactions easier to write // and, thus, there's the potential to make mistakes that the generated data model would not make. if (this.RowState == DataRowState.Detached) { throw new LockException(String.Format(CultureInfo.CurrentCulture, Properties.Resources.DeletedAfterLockedError, this.GetType())); } }
/// <summary> /// Acquires a reader lock for this record. /// </summary> /// <param name="dataModelTransaction">The transaction context for this operation.</param> //[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] public virtual void AcquireReaderLock(IDataModelTransaction dataModelTransaction) { global::System.Guid transactionId = dataModelTransaction.TransactionId; try { global::System.Threading.Monitor.Enter(this.rowRoot); this.readerWaiters = (this.readerWaiters + 1); if ((this.writer != transactionId)) { for ( ; (this.writer != global::System.Guid.Empty); ) { if (false == global::System.Threading.Monitor.Wait(this.rowRoot, this.LockTimeout)) { try { EventLog.Information("AcquireReaderLock DEGRADE from TIMEOUT\r\n {0} Current Stack: {1} \r\n{2}", this.GetRowDebugDescription(), UnhandledExceptionHelper.GetStackString(), this.GetCurrentLockStacks(false)); } catch { } break; } } int index = this._readers.BinarySearch(transactionId); if ((index < 0)) { InsertToReaderList(transactionId, index); } } } finally { this.readerWaiters = (this.readerWaiters - 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"); } }
/// <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"); } }