コード例 #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
ファイル: Threading.cs プロジェクト: GlennSandoval/JSIL
            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
ファイル: FunctionCache.cs プロジェクト: cbsistem/JSIL
            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
ファイル: Threading.cs プロジェクト: GlennSandoval/JSIL
        public DeadlockAvertedException (TrackedLock lock1, TrackedLock lock2)
            : base("The operation would have caused a deadlock.") {

            Lock1 = lock1;
            Lock2 = lock2;
        }
コード例 #12
0
ファイル: Threading.cs プロジェクト: GlennSandoval/JSIL
 public DeadlockInfo (TrackedLock a, TrackedLock b) {
     A = a;
     B = b;
 }
コード例 #13
0
ファイル: Threading.cs プロジェクト: GlennSandoval/JSIL
        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);
        }