示例#1
0
 internal void Track(TrackedLock lck)
 {
     if (!Locks.TryAdd(lck, false))
     {
         throw new ThreadStateException();
     }
 }
示例#2
0
        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();
                }
            }
        }
示例#3
0
            public Wait (TrackedLockCollection collection, TrackedLock lck, Thread thread) {
                Collection = collection;
                Lock = lck;
                Thread = thread;

                if (!Collection.WaitsByThread.TryAdd(thread, this))
                    throw new ThreadStateException();
            }
示例#4
0
            public Wait(TrackedLockCollection collection, TrackedLock lck, Thread thread)
            {
                Collection = collection;
                Lock       = lck;
                Thread     = thread;

                if (!Collection.WaitsByThread.TryAdd(thread, this))
                {
                    throw new ThreadStateException();
                }
            }
示例#5
0
        internal int GetWaitingThreadCount(TrackedLock lck)
        {
            OrderedDictionary <Wait, bool> waits;

            if (!Waits.TryGet(lck, out waits))
            {
                return(0);
            }

            lock (waits)
                return(waits.Count);
        }
示例#6
0
        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));
        }
示例#7
0
        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);
        }
示例#8
0
            public Entry (QualifiedMemberIdentifier identifier, TrackedLockCollection lockCollection) {
                Identifier = identifier;

                StaticAnalysisDataLock = new TrackedLock(lockCollection, () => String.Format("{0}", this.Identifier.ToString()));
            }
示例#9
0
 public DeadlockAvertedException(TrackedLock lock1, TrackedLock lock2)
     : base("The operation would have caused a deadlock.")
 {
     Lock1 = lock1;
     Lock2 = lock2;
 }
示例#10
0
 public DeadlockInfo(TrackedLock a, TrackedLock b)
 {
     A = a;
     B = b;
 }
示例#11
0
        public DeadlockAvertedException (TrackedLock lock1, TrackedLock lock2)
            : base("The operation would have caused a deadlock.") {

            Lock1 = lock1;
            Lock2 = lock2;
        }
示例#12
0
 public DeadlockInfo (TrackedLock a, TrackedLock b) {
     A = a;
     B = b;
 }
示例#13
0
        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);
        }