internal void Track(TrackedLock lck) { if (!Locks.TryAdd(lck, false)) { throw new ThreadStateException(); } }
internal void Untrack(TrackedLock lck) { bool temp; if (!Locks.TryRemove(lck, out temp)) { throw new ThreadStateException(); } OrderedDictionary <Wait, bool> waits; if (Waits.TryGet(lck, out waits)) { lock (waits) { foreach (var w in waits) { w.Key.Dispose(); } waits.Clear(); } if (!Waits.TryRemove(lck)) { throw new ThreadStateException(); } } }
public Wait (TrackedLockCollection collection, TrackedLock lck, Thread thread) { Collection = collection; Lock = lck; Thread = thread; if (!Collection.WaitsByThread.TryAdd(thread, this)) throw new ThreadStateException(); }
public Wait(TrackedLockCollection collection, TrackedLock lck, Thread thread) { Collection = collection; Lock = lck; Thread = thread; if (!Collection.WaitsByThread.TryAdd(thread, this)) { throw new ThreadStateException(); } }
internal int GetWaitingThreadCount(TrackedLock lck) { OrderedDictionary <Wait, bool> waits; if (!Waits.TryGet(lck, out waits)) { return(0); } lock (waits) return(waits.Count); }
internal bool TryDequeueOneWait(TrackedLock lck, out Wait wait) { wait = null; OrderedDictionary <Wait, bool> waits; if (!Waits.TryGet(lck, out waits)) { return(false); } bool temp; lock (waits) return(waits.TryDequeueFirst(out wait, out temp)); }
internal bool TryCreateWait(TrackedLock lck, out DeadlockInfo deadlock, out Wait wait) { var currentThread = Thread.CurrentThread; var waits = Waits.GetOrCreate(lck, MakeWaitList); wait = new Wait(this, lck, currentThread); lock (waits) waits.Enqueue(wait, false); deadlock = DetectDeadlock(wait); if (deadlock != null) { lock (waits) waits.Remove(wait); var wasSignaled = wait.IsSignaled; wait.Dispose(); wait = null; // It's possible, albeit incredibly unlikely, for someone to call Wake on our wait // before we do the deadlock check. // If this happens, try to dequeue another wait from the queue and wake it up in our stead. // This can probably still break, though... if (wasSignaled) { if (TryDequeueOneWait(lck, out wait)) { wait.Wake(); } } return(false); } return(true); }
public Entry (QualifiedMemberIdentifier identifier, TrackedLockCollection lockCollection) { Identifier = identifier; StaticAnalysisDataLock = new TrackedLock(lockCollection, () => String.Format("{0}", this.Identifier.ToString())); }
public DeadlockAvertedException(TrackedLock lock1, TrackedLock lock2) : base("The operation would have caused a deadlock.") { Lock1 = lock1; Lock2 = lock2; }
public DeadlockInfo(TrackedLock a, TrackedLock b) { A = a; B = b; }
public DeadlockAvertedException (TrackedLock lock1, TrackedLock lock2) : base("The operation would have caused a deadlock.") { Lock1 = lock1; Lock2 = lock2; }
public DeadlockInfo (TrackedLock a, TrackedLock b) { A = a; B = b; }
internal bool TryDequeueOneWait (TrackedLock lck, out Wait wait) { wait = null; OrderedDictionary<Wait, bool> waits; if (!Waits.TryGet(lck, out waits)) return false; bool temp; lock (waits) return waits.TryDequeueFirst(out wait, out temp); }