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()); }
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); } }
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 }
internal static void ThreadContract(ThreadKinds kind, ThreadKinds allowedSources, string errorMsg) { if (((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown) || ((allowedSources & ThreadKinds.SourceMask) != allowedSources)) { throw new InternalException(); } ThreadKinds currentThreadKind = CurrentThreadKind; }
internal static IDisposable?SetThreadKind(ThreadKinds kind) { if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown) { throw new InternalException(kind); } // Ignore during shutdown. if (Environment.HasShutdownStarted) { return(null); } ThreadKinds threadKind = CurrentThreadKind; ThreadKinds source = threadKind & ThreadKinds.SourceMask; // Special warnings when doing dangerous things on a thread. if ((threadKind & ThreadKinds.User) != 0 && (kind & ThreadKinds.System) != 0) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, "Thread changed from User to System; user's thread shouldn't be hijacked."); } } if ((threadKind & ThreadKinds.Async) != 0 && (kind & ThreadKinds.Sync) != 0) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, "Thread changed from Async to Sync, may block an Async thread."); } } else if ((threadKind & (ThreadKinds.Other | ThreadKinds.CompletionPort)) == 0 && (kind & ThreadKinds.Sync) != 0) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, "Thread from a limited resource changed to Sync, may deadlock or bottleneck."); } } 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 (CurrentThreadKind != threadKind) { if (NetEventSource.IsEnabled) { NetEventSource.Info(null, $"Thread becomes:({CurrentThreadKind})"); } } return(new ThreadKindFrame()); }
internal static void ThreadContract(ThreadKinds kind, ThreadKinds allowedSources, string errorMsg) { if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown || (allowedSources & ThreadKinds.SourceMask) != allowedSources) { throw new InternalException(); } ThreadKinds threadKind = CurrentThreadKind; Assert((threadKind & allowedSources) != 0, errorMsg, "Thread Contract Violation.|Expected source:({0}) Actual source:({1})", allowedSources, threadKind & ThreadKinds.SourceMask); Assert((threadKind & kind) == kind, errorMsg, "Thread Contract Violation.|Expected kind:({0}) Actual kind:({1})", kind, threadKind & ~ThreadKinds.SourceMask); }
void IDisposable.Dispose() { // Ignore during shutdown. if (NclUtilities.HasShutdownStarted) { return; } if (m_FrameNumber != ThreadKindStack.Count) { throw new InternalException(); } ThreadKinds previous = ThreadKindStack.Pop(); }
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()); }
internal static IDisposable SetThreadKind(ThreadKinds kind) { if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown) { throw new InternalException(); } // Ignore during shutdown. if (Environment.HasShutdownStarted) { return null; } ThreadKinds threadKind = CurrentThreadKind; ThreadKinds source = threadKind & ThreadKinds.SourceMask; // Special warnings when doing dangerous things on a thread. if ((threadKind & ThreadKinds.User) != 0 && (kind & ThreadKinds.System) != 0) { EventSourceLogging.Log.WarningMessage("Thread changed from User to System; user's thread shouldn't be hijacked."); } if ((threadKind & ThreadKinds.Async) != 0 && (kind & ThreadKinds.Sync) != 0) { EventSourceLogging.Log.WarningMessage("Thread changed from Async to Sync, may block an Async thread."); } else if ((threadKind & (ThreadKinds.Other | ThreadKinds.CompletionPort)) == 0 && (kind & ThreadKinds.Sync) != 0) { EventSourceLogging.Log.WarningMessage("Thread from a limited resource changed to Sync, may deadlock or bottleneck."); } 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 (CurrentThreadKind != threadKind) { Print("Thread becomes:(" + CurrentThreadKind.ToString() + ")"); } return new ThreadKindFrame(); }
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() + ")"); } }
internal static void ThreadContract(ThreadKinds kind, ThreadKinds allowedSources, string errorMsg) { if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown || (allowedSources & ThreadKinds.SourceMask) != allowedSources) { throw new InternalException(); } if (NetEventSource.IsEnabled) { ThreadKinds threadKind = CurrentThreadKind; if ((threadKind & allowedSources) != 0) { NetEventSource.Fail(null, $"Thread Contract Violation.|Expected source:({allowedSources}) Actual source:({threadKind & ThreadKinds.SourceMask})"); } if ((threadKind & kind) == kind) { NetEventSource.Fail(null, $"Thread Contract Violation.|Expected kind:({kind}) Actual kind:({threadKind & ~ThreadKinds.SourceMask})"); } } }
internal static void SetThreadSource(ThreadKinds source) { if ((source & ThreadKinds.SourceMask) != source || source == ThreadKinds.Unknown) { throw new ArgumentException("Must specify the thread source.", nameof(source)); } if (ThreadKindStack.Count == 0) { ThreadKindStack.Push(source); return; } if (ThreadKindStack.Count > 1) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, "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) { if (NetEventSource.IsEnabled) { NetEventSource.Error(null, "The stack has been corrupted."); } ThreadKinds last = ThreadKindStack.Pop() & ThreadKinds.SourceMask; if (last != source && last != ThreadKinds.Other && NetEventSource.IsEnabled) { NetEventSource.Fail(null, $"Thread source changed.|Was:({last}) Now:({source})"); } ThreadKindStack.Push(source); } }
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 }
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})"); } } }
internal static void ThreadContract(ThreadKinds kind, string errorMsg) { ThreadContract(kind, ThreadKinds.SafeSources, errorMsg); }
internal static void ThreadContract(ThreadKinds kind, string errorMsg) { }
internal static void SetThreadSource(ThreadKinds source) { }
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(); }
internal static void SetThreadSource(ThreadKinds source) { if ((source & ThreadKinds.SourceMask) != source || source == ThreadKinds.Unknown) { throw new ArgumentException("Must specify the thread source.", nameof(source)); } if (ThreadKindStack.Count == 0) { ThreadKindStack.Push(source); return; } if (ThreadKindStack.Count > 1) { if (NetEventSource.IsEnabled) NetEventSource.Error(null, "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) { if (NetEventSource.IsEnabled) NetEventSource.Error(null, "The stack has been corrupted."); ThreadKinds last = ThreadKindStack.Pop() & ThreadKinds.SourceMask; if (last != source && last != ThreadKinds.Other && NetEventSource.IsEnabled) { NetEventSource.Fail(null, $"Thread source changed.|Was:({last}) Now:({source})"); } ThreadKindStack.Push(source); } }
internal static void SetThreadSource(ThreadKinds source) { if ((source & ThreadKinds.SourceMask) != source || source == ThreadKinds.Unknown) { throw new ArgumentException("Must specify the thread source.", nameof(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; if (last != source && last != ThreadKinds.Other && IsEnabled) { AssertFormat("Thread source changed.|Was:({0}) Now:({1})", last, source); } ThreadKindStack.Push(source); } }
internal static void ThreadContract(ThreadKinds kind, ThreadKinds allowedSources, string errorMsg) { if ((kind & ThreadKinds.SourceMask) != ThreadKinds.Unknown || (allowedSources & ThreadKinds.SourceMask) != allowedSources) { throw new InternalException(); } ThreadKinds threadKind = CurrentThreadKind; Assert((threadKind & allowedSources) != 0, errorMsg, "Thread Contract Violation.|Expected source:({0}) Actual source:({1})", allowedSources , threadKind & ThreadKinds.SourceMask); Assert((threadKind & kind) == kind, errorMsg, "Thread Contract Violation.|Expected kind:({0}) Actual kind:({1})", kind, threadKind & ~ThreadKinds.SourceMask); }