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); } } } }
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); }
internal void Exit() { try { HeldLocks.Remove(this); } finally { Monitor.Exit(this); } }
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); }
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); }
internal static void AssertIsLocked(InstanceLock theLock) { #if DEBUG System.Diagnostics.Debug.Assert(HeldLocks.Contains(theLock), "Lock should be held."); #endif }