Exemplo n.º 1
0
        internal bool TryEnter()
        {
            InstanceLockGuard.EnforceGuard(this);

            bool lockHeld = false;
            bool success  = false;

            try
            {
                Monitor.TryEnter(this, ref lockHeld);

                if (lockHeld)
                {
                    HeldLocks.Add(this);
                    success = true;
                }
            }
            finally
            {
                if (lockHeld && !success)
                {
                    Monitor.Exit(this);
                }
            }
            return(success);
        }
Exemplo n.º 2
0
            internal InstanceLockGuard(InstanceLock theLock)
            {
                this.m_lock = theLock;

                // Note: the following operations are logically atomic, but since the
                // list we are using is thread local there is no need to take a lock.

                EnforceGuard(theLock);

                try
                {
                }
                finally
                {
                    bool success = false;
#pragma warning disable 0618
//@
                    Monitor.Enter(this.m_lock);
#pragma warning restore 0618
                    try
                    {
                        HeldLocks.Add(this.m_lock);
                        success = true;
                    }
                    finally
                    {
                        if (!success)
                        {
                            Monitor.Exit(this.m_lock);
                        }
                    }
                }
            }
Exemplo n.º 3
0
        internal bool TryEnter()
        {
            InstanceLockGuard.EnforceGuard(this);
            bool lockTaken = false;
            bool flag2     = false;

            try
            {
                Monitor.TryEnter(this, ref lockTaken);
                if (lockTaken)
                {
                    HeldLocks.Add(this);
                    flag2 = true;
                }
            }
            finally
            {
                if (lockTaken && !flag2)
                {
                    Monitor.Exit(this);
                }
            }
            return(flag2);
        }