コード例 #1
0
        /// <summary>
        /// Handler executed after execution of the method to which the current custom attribute is applied.
        /// </summary>
        /// <param name="eventArgs"></param>
        public override void OnExit(MethodExecutionArgs eventArgs)
        {
            object o = eventArgs.Instance ?? eventArgs.Method.DeclaringType;

            Monitor.Exit(o);
            DeadlockMonitor.ExitAcquired(o, null);
        }
コード例 #2
0
            /// <inheritdoc />
            public void Dispose()
            {
                switch (this.action)
                {
                case CookieAction.None:
                    break;

                case CookieAction.ExitReadLock:
                    [email protected]();
                    DeadlockMonitor.ExitAcquired(this.parent.@lock, readLock);
                    break;

                case CookieAction.ExitWriteLock:
                    [email protected]();
                    DeadlockMonitor.ExitAcquired(this.parent.@lock, writeLock);
                    break;

                case CookieAction.ExitWriteAndUpgradeableReadLock:
                    [email protected]();
                    [email protected]();
                    DeadlockMonitor.ExitAcquired(this.parent.@lock, writeLock);
                    DeadlockMonitor.ExitAcquired(this.parent.@lock, upgradableReadLock);
                    break;

                case CookieAction.EnterWriteLock:
                    DeadlockMonitor.EnterWaiting(this.parent.@lock, readLock, this.parent.lockedObject);
                    DeadlockMonitor.EnterWaiting(this.parent.@lock, writeLock, this.parent.lockedObject);
                    DeadlockMonitor.EnterWaiting(this.parent.@lock, upgradableReadLock, this.parent.lockedObject);

                    if ([email protected](WarningTimeout))
                    {
                        Debug.Print("Reacquiring a write lock on {0} from thread {1} ({2}) is taking longer than expected.",
                                    this.parent.lockedObject, Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.Name);
                        DeadlockMonitor.DetectDeadlocks();
                        [email protected]();
                    }
                    DeadlockMonitor.ConvertWaitingToAcquired(this.parent.@lock, writeLock, this.parent.lockedObject);
                    DeadlockMonitor.ExitWaiting(this.parent.@lock, readLock);
                    DeadlockMonitor.ExitWaiting(this.parent.@lock, upgradableReadLock);

                    break;

                case CookieAction.ExitUpgrableReaderLock:
                    [email protected]();
                    DeadlockMonitor.ExitAcquired(this.parent.@lock, upgradableReadLock);
                    break;
                }

                this.action = CookieAction.None;

                GC.SuppressFinalize(this);
            }
コード例 #3
0
        /// <summary>
        /// Acquires an observer lock.
        /// </summary>
        /// <returns>An object (considered opaque by client code) that should be disposed
        /// once the lock is not needed.</returns>
        /// <remarks>It is strongly recommended to use the <b>using</b> construct with
        /// this method.</remarks>
        public Cookie AcquireObserverLock()
        {
            if (this.@lock == null)
            {
                return(new Cookie(CookieAction.None, null, null));
            }

            if ([email protected])
            {
                [email protected]();
                DeadlockMonitor.ExitAcquired(this.@lock, writeLock);
                return(new Cookie(CookieAction.EnterWriteLock, this, GetStackTrace()));
            }
            else
            {
                return(new Cookie(CookieAction.None, this, GetStackTrace()));
            }
        }