Exemple #1
0
        internal static void SetThreadSource(ThreadKinds source)
        {
            if ((source & ThreadKinds.SourceMask) != source || source == ThreadKinds.Unknown)
            {
                throw new ArgumentException("Must specify the thread source.", "source");
            }

            if (ThreadKindStack.Count == 0)
            {
                ThreadKindStack.Push(source);
                return;
            }

            if (ThreadKindStack.Count > 1)
            {
                EventSourceLogging.Log.WarningMessage("SetThreadSource must be called at the base of the stack, or the stack has been corrupted.");
                while (ThreadKindStack.Count > 1)
                {
                    ThreadKindStack.Pop();
                }
            }

            if (ThreadKindStack.Peek() != source)
            {
                EventSourceLogging.Log.WarningMessage("The stack has been corrupted.");
                ThreadKinds last = ThreadKindStack.Pop() & ThreadKinds.SourceMask;
                Assert(last == source || last == ThreadKinds.Other, "Thread source changed.|Was:({0}) Now:({1})", last, source);
                ThreadKindStack.Push(source);
            }
        }
Exemple #2
0
        internal static void SetThreadSource(ThreadKinds source)
        {
#if DEBUG
            if ((source & ThreadKinds.SourceMask) != source || source == ThreadKinds.Unknown)
            {
                throw new ArgumentException("Must specify the thread source.", "source");
            }

            if (ThreadKindStack.Count == 0)
            {
                ThreadKindStack.Push(source);
                return;
            }

            if (ThreadKindStack.Count > 1)
            {
                Print("WARNING: SetThreadSource must be called at the base of the stack, or the stack has been corrupted.");
                while (ThreadKindStack.Count > 1)
                {
                    ThreadKindStack.Pop();
                }
            }

            if (ThreadKindStack.Peek() != source)
            {
                // SQL can fail to clean up the stack, leaving the default Other at the bottom.  Replace it.
                Print("WARNING: The stack has been corrupted.");
                ThreadKinds last = ThreadKindStack.Pop() & ThreadKinds.SourceMask;
                Assert(last == source || last == ThreadKinds.Other, "Thread source changed.|Was:({0}) Now:({1})", last, source);
                ThreadKindStack.Push(source);
            }
#endif
        }
Exemple #3
0
        internal static IDisposable SetThreadKind(ThreadKinds kind)
        {
            if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown)
            {
                throw new InternalException();
            }

            // Ignore during shutdown.
            if (NclUtilities.HasShutdownStarted)
            {
                return(null);
            }

            ThreadKinds threadKind = CurrentThreadKind;
            ThreadKinds source     = threadKind & ThreadKinds.SourceMask;


            ThreadKindStack.Push(
                (((kind & ThreadKinds.OwnerMask) == 0 ? threadKind : kind) & ThreadKinds.OwnerMask) |
                (((kind & ThreadKinds.SyncMask) == 0 ? threadKind : kind) & ThreadKinds.SyncMask) |
                (kind & ~(ThreadKinds.OwnerMask | ThreadKinds.SyncMask)) |
                source);


            return(new ThreadKindFrame());
        }
Exemple #4
0
            void IDisposable.Dispose()
            {
                // Ignore during shutdown.
                if (NclUtilities.HasShutdownStarted)
                {
                    return;
                }

                if (m_FrameNumber != ThreadKindStack.Count)
                {
                    throw new InternalException();
                }

                ThreadKinds previous = ThreadKindStack.Pop();
            }
Exemple #5
0
        internal static IDisposable SetThreadKind(ThreadKinds kind)
        {
            if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown)
            {
                throw new InternalException();
            }

            // Ignore during shutdown.
            if (NclUtilities.HasShutdownStarted)
            {
                return(null);
            }

            ThreadKinds threadKind = CurrentThreadKind;
            ThreadKinds source     = threadKind & ThreadKinds.SourceMask;

#if TRAVE
            // Special warnings when doing dangerous things on a thread.
            if ((threadKind & ThreadKinds.User) != 0 && (kind & ThreadKinds.System) != 0)
            {
                Print("WARNING: Thread changed from User to System; user's thread shouldn't be hijacked.");
            }

            if ((threadKind & ThreadKinds.Async) != 0 && (kind & ThreadKinds.Sync) != 0)
            {
                Print("WARNING: Thread changed from Async to Sync, may block an Async thread.");
            }
            else if ((threadKind & (ThreadKinds.Other | ThreadKinds.CompletionPort)) == 0 && (kind & ThreadKinds.Sync) != 0)
            {
                Print("WARNING: Thread from a limited resource changed to Sync, may deadlock or bottleneck.");
            }
#endif

            ThreadKindStack.Push(
                (((kind & ThreadKinds.OwnerMask) == 0 ? threadKind : kind) & ThreadKinds.OwnerMask) |
                (((kind & ThreadKinds.SyncMask) == 0 ? threadKind : kind) & ThreadKinds.SyncMask) |
                (kind & ~(ThreadKinds.OwnerMask | ThreadKinds.SyncMask)) |
                source);

#if TRAVE
            if (CurrentThreadKind != threadKind)
            {
                Print("Thread becomes:(" + CurrentThreadKind.ToString() + ")");
            }
#endif

            return(new ThreadKindFrame());
        }
Exemple #6
0
            void IDisposable.Dispose()
            {
                // Ignore during shutdown.
                if (Environment.HasShutdownStarted)
                {
                    return;
                }

                if (_frameNumber != ThreadKindStack.Count)
                {
                    throw new InternalException();
                }

                ThreadKinds previous = ThreadKindStack.Pop();

                if (CurrentThreadKind != previous)
                {
                    Print("Thread reverts:(" + CurrentThreadKind.ToString() + ")");
                }
            }
Exemple #7
0
            void IDisposable.Dispose()
            {
                // Ignore during shutdown.
                if (NclUtilities.HasShutdownStarted)
                {
                    return;
                }

                if (m_FrameNumber != ThreadKindStack.Count)
                {
                    throw new InternalException();
                }

                ThreadKinds previous = ThreadKindStack.Pop();

#if TRAVE
                if (CurrentThreadKind != previous)
                {
                    Print("Thread reverts:(" + CurrentThreadKind.ToString() + ")");
                }
#endif
            }
Exemple #8
0
            void IDisposable.Dispose()
            {
                // Ignore during shutdown.
                if (Environment.HasShutdownStarted)
                {
                    return;
                }

                if (_frameNumber != ThreadKindStack.Count)
                {
                    throw new InternalException(_frameNumber);
                }

                ThreadKinds previous = ThreadKindStack.Pop();

                if (CurrentThreadKind != previous && NetEventSource.IsEnabled)
                {
                    if (NetEventSource.IsEnabled)
                    {
                        NetEventSource.Info(this, $"Thread reverts:({CurrentThreadKind})");
                    }
                }
            }