Exemplo n.º 1
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.º 2
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.º 3
0
 internal void Exit()
 {
     try
     {
         HeldLocks.Remove(this);
     }
     finally
     {
         Monitor.Exit(this);
     }
 }
Exemplo n.º 4
0
 public void Dispose()
 {
     // 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.
     try
     {
         HeldLocks.Remove(this.m_lock);
     }
     finally
     {
         Monitor.Exit(this.m_lock);
     }
 }
            /// <summary>
            /// Dispose, unlock the lock, reset state.
            /// </summary>
            public void Dispose()
            {
#if DEBUG
                if (!_recLock)
                {
                    _lockInfo.OwningThread = -1;
                }

                Debug.Assert(HeldLocks.Peek() == _lockInfo, "Can not dispose lock not owned.");
                HeldLocks.Pop();
#endif
                Monitor.Exit(_object);
                GC.SuppressFinalize(this);
            }
Exemplo n.º 6
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);
        }
Exemplo n.º 7
0
        internal static void AssertIsLocked(InstanceLock theLock)
        {
#if DEBUG
            System.Diagnostics.Debug.Assert(HeldLocks.Contains(theLock), "Lock should be held.");
#endif
        }