Skip to content

Commit a38b54a

Browse files
committed
tweaks
1 parent 970438f commit a38b54a

File tree

3 files changed

+24
-26
lines changed

3 files changed

+24
-26
lines changed

src/coreclr/vm/threads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5850,7 +5850,7 @@ BOOL ThreadStore::DbgFindThread(Thread *target)
58505850
// return).
58515851
//
58525852
// Note: we don't actually assert this if
5853-
// ThreadStore::TrapReturningThreadsIncrement() updated g_TrapReturningThreads
5853+
// ThreadStore::IncrementTrapReturningThreads() updated g_TrapReturningThreads
58545854
// between the beginning of this function and the moment of the assert.
58555855
// *** The order of evaluation in the if condition is important ***
58565856
_ASSERTE(

src/coreclr/vm/threads.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4152,14 +4152,14 @@ class ThreadStore
41524152
}
41534153

41544154
// If you want to trap threads re-entering the EE (for debugging,
4155-
// or Thread.Suspend() or whatever, you need to TrapReturningThreadsIncrement(). When
4156-
// you are finished snagging threads, call TrapReturningThreadsDecrement(). This
4155+
// or Thread.Suspend() or whatever, you need to IncrementTrapReturningThreads(). When
4156+
// you are finished snagging threads, call DecrementTrapReturningThreads(). This
41574157
// counts internally.
41584158
//
41594159
// Of course, you must also fix RareDisablePreemptiveGC to do the right thing
41604160
// when the trap occurs.
4161-
static void TrapReturningThreadsIncrement();
4162-
static void TrapReturningThreadsDecrement();
4161+
static void IncrementTrapReturningThreads();
4162+
static void DecrementTrapReturningThreads();
41634163

41644164
static void SetThreadTrapForSuspension();
41654165
static void UnsetThreadTrapForSuspension();
@@ -4327,8 +4327,8 @@ class ThreadStore
43274327
};
43284328

43294329
struct TSSuspendHelper {
4330-
static void SetTrap() { ThreadStore::TrapReturningThreadsIncrement(); }
4331-
static void UnsetTrap() { ThreadStore::TrapReturningThreadsDecrement(); }
4330+
static void SetTrap() { ThreadStore::IncrementTrapReturningThreads(); }
4331+
static void UnsetTrap() { ThreadStore::DecrementTrapReturningThreads(); }
43324332
};
43334333
typedef StateHolder<TSSuspendHelper::SetTrap, TSSuspendHelper::UnsetTrap> TSSuspendHolder;
43344334

@@ -4519,7 +4519,7 @@ inline void Thread::MarkForDebugSuspend(void)
45194519
if (!HasThreadState(TS_DebugSuspendPending))
45204520
{
45214521
SetThreadState(TS_DebugSuspendPending);
4522-
ThreadStore::TrapReturningThreadsIncrement();
4522+
ThreadStore::IncrementTrapReturningThreads();
45234523
}
45244524
}
45254525

@@ -4530,13 +4530,13 @@ inline void Thread::IncrementTraceCallCount()
45304530
{
45314531
WRAPPER_NO_CONTRACT;
45324532
InterlockedIncrement(&m_TraceCallCount);
4533-
ThreadStore::TrapReturningThreadsIncrement();
4533+
ThreadStore::IncrementTrapReturningThreads();
45344534
}
45354535

45364536
inline void Thread::DecrementTraceCallCount()
45374537
{
45384538
WRAPPER_NO_CONTRACT;
4539-
ThreadStore::TrapReturningThreadsDecrement();
4539+
ThreadStore::DecrementTrapReturningThreads();
45404540
InterlockedDecrement(&m_TraceCallCount);
45414541
}
45424542

src/coreclr/vm/threadsuspend.cpp

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ Thread::UserAbort(EEPolicy::ThreadAbortTypes abortType, DWORD timeout)
12951295
// The thread being aborted may clear the TS_AbortRequested bit and the matching increment
12961296
// of g_TrapReturningThreads behind our back. Increment g_TrapReturningThreads here
12971297
// to ensure that we stop for the stack crawl even if the TS_AbortRequested bit is cleared.
1298-
ThreadStore::TrapReturningThreadsIncrement();
1298+
ThreadStore::IncrementTrapReturningThreads();
12991299
}
13001300
void NeedStackCrawl()
13011301
{
@@ -1310,7 +1310,7 @@ Thread::UserAbort(EEPolicy::ThreadAbortTypes abortType, DWORD timeout)
13101310
if (m_NeedRelease)
13111311
{
13121312
m_NeedRelease = FALSE;
1313-
ThreadStore::TrapReturningThreadsDecrement();
1313+
ThreadStore::DecrementTrapReturningThreads();
13141314
ThreadStore::SetStackCrawlEvent();
13151315
m_pThread->ResetThreadState(TS_StackCrawlNeeded);
13161316
if (!m_fHoldingThreadStoreLock)
@@ -1755,7 +1755,7 @@ void Thread::SetAbortRequestBit()
17551755
}
17561756
if (InterlockedCompareExchange((LONG*)&m_State, curValue|TS_AbortRequested, curValue) == curValue)
17571757
{
1758-
ThreadStore::TrapReturningThreadsIncrement();
1758+
ThreadStore::IncrementTrapReturningThreads();
17591759

17601760
break;
17611761
}
@@ -1771,7 +1771,7 @@ void Thread::RemoveAbortRequestBit()
17711771

17721772
#ifdef _DEBUG
17731773
// There's a race between removing the TS_AbortRequested bit and decrementing g_TrapReturningThreads
1774-
// We may remove the bit, but before we have a chance to call ThreadStore::TrapReturningThreadsDecrement()
1774+
// We may remove the bit, but before we have a chance to call ThreadStore::DecrementTrapReturningThreads()
17751775
// DbgFindThread() may execute, and find too few threads with the bit set.
17761776
// To ensure the assert in DbgFindThread does not fire under such a race we set the ChgInFlight before hand.
17771777
CounterHolder trtHolder(&g_trtChgInFlight);
@@ -1785,7 +1785,7 @@ void Thread::RemoveAbortRequestBit()
17851785
}
17861786
if (InterlockedCompareExchange((LONG*)&m_State, curValue&(~TS_AbortRequested), curValue) == curValue)
17871787
{
1788-
ThreadStore::TrapReturningThreadsDecrement();
1788+
ThreadStore::DecrementTrapReturningThreads();
17891789

17901790
break;
17911791
}
@@ -2113,7 +2113,7 @@ void Thread::RareDisablePreemptiveGC()
21132113
if (ThreadStore::HoldingThreadStore(this))
21142114
{
21152115
// In theory threads should not try entering coop mode while holding TS lock,
2116-
// but some scenarios like GCCoopHackNoThread end up here
2116+
// but some scenarios like GCCoopHackNoThread and GCX_COOP_NO_THREAD_BROKEN end up here
21172117
goto Exit;
21182118
}
21192119

@@ -2143,7 +2143,7 @@ void Thread::RareDisablePreemptiveGC()
21432143
{
21442144
#ifdef DEBUGGING_SUPPORTED
21452145
// If debugger wants the thread to suspend, give the debugger precedence.
2146-
if ((m_State & TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion())
2146+
if (HasThreadStateOpportunistic(TS_DebugSuspendPending) && !IsInForbidSuspendForDebuggerRegion())
21472147
{
21482148
EnablePreemptiveGC();
21492149

@@ -2214,7 +2214,7 @@ void Thread::RareDisablePreemptiveGC()
22142214
continue;
22152215
}
22162216

2217-
if (HasThreadState(TS_StackCrawlNeeded))
2217+
if (HasThreadStateOpportunistic(TS_StackCrawlNeeded))
22182218
{
22192219
EnablePreemptiveGC();
22202220
ThreadStore::WaitForStackCrawlEvent();
@@ -2394,7 +2394,7 @@ void Thread::PulseGCMode()
23942394
// Indicate whether threads should be trapped when returning to the EE (i.e. disabling
23952395
// preemptive GC mode)
23962396
Volatile<LONG> g_fTrapReturningThreadsLock;
2397-
void ThreadStore::TrapReturningThreadsIncrement()
2397+
void ThreadStore::IncrementTrapReturningThreads()
23982398
{
23992399
CONTRACTL {
24002400
NOTHROW;
@@ -2432,7 +2432,7 @@ void ThreadStore::TrapReturningThreadsIncrement()
24322432
g_fTrapReturningThreadsLock = 0;
24332433
}
24342434

2435-
void ThreadStore::TrapReturningThreadsDecrement()
2435+
void ThreadStore::DecrementTrapReturningThreads()
24362436
{
24372437
CONTRACTL {
24382438
NOTHROW;
@@ -3210,14 +3210,14 @@ COR_PRF_SUSPEND_REASON GCSuspendReasonToProfSuspendReason(ThreadSuspend::SUSPEND
32103210
}
32113211
#endif // PROFILING_SUPPORTED
32123212

3213-
int64_t QueryPerformanceCounter()
3213+
static int64_t QueryPerformanceCounter()
32143214
{
32153215
LARGE_INTEGER ts;
32163216
QueryPerformanceCounter(&ts);
32173217
return ts.QuadPart;
32183218
}
32193219

3220-
int64_t QueryPerformanceFrequency()
3220+
static int64_t QueryPerformanceFrequency()
32213221
{
32223222
LARGE_INTEGER ts;
32233223
QueryPerformanceFrequency(&ts);
@@ -3596,8 +3596,6 @@ void EnableStressHeapHelper()
35963596
}
35973597
#endif
35983598

3599-
// We're done with our GC. Let all the threads run again.
3600-
// By this point we've already unblocked most threads. This just releases the ThreadStore lock.
36013599
void ThreadSuspend::ResumeAllThreads(BOOL SuspendSucceeded)
36023600
{
36033601
CONTRACTL {
@@ -5359,7 +5357,7 @@ void Thread::MarkForSuspension(ULONG bit)
53595357
_ASSERTE((m_State & bit) == 0);
53605358

53615359
InterlockedOr((LONG*)&m_State, bit);
5362-
ThreadStore::TrapReturningThreadsIncrement();
5360+
ThreadStore::IncrementTrapReturningThreads();
53635361
}
53645362

53655363
void Thread::UnmarkForSuspension(ULONG mask)
@@ -5378,7 +5376,7 @@ void Thread::UnmarkForSuspension(ULONG mask)
53785376
_ASSERTE((m_State & ~mask) != 0);
53795377

53805378
// we decrement the global first to be able to satisfy the assert from DbgFindThread
5381-
ThreadStore::TrapReturningThreadsDecrement();
5379+
ThreadStore::DecrementTrapReturningThreads();
53825380
InterlockedAnd((LONG*)&m_State, mask);
53835381
}
53845382

0 commit comments

Comments
 (0)