Skip to content

Commit 80e8250

Browse files
Try to fix GCPoll regression.
1 parent c8c238f commit 80e8250

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

src/coreclr/System.Private.CoreLib/src/System/Threading/Thread.CoreCLR.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -491,6 +491,9 @@ private void ResetFinalizerThreadSlow()
491491
}
492492
}
493493

494+
[MethodImpl(MethodImplOptions.InternalCall)]
495+
private static extern bool CatchAtSafePoint();
496+
494497
[LibraryImport(RuntimeHelpers.QCall, EntryPoint = "ThreadNative_PollGC")]
495498
private static partial void PollGCInternal();
496499

@@ -499,8 +502,7 @@ private void ResetFinalizerThreadSlow()
499502
// as a small assembly stub which checks the global g_TrapReturningThreads flag and tail-call to this helper
500503
private static unsafe void PollGC()
501504
{
502-
NativeThreadState catchAtSafePoint = ((NativeThreadClass*)Thread.DirectOnThreadLocalData.pNativeThread)->m_State & NativeThreadState.TS_CatchAtSafePoint;
503-
if (catchAtSafePoint != NativeThreadState.None)
505+
if (CatchAtSafePoint())
504506
{
505507
PollGCWorker();
506508
}

src/coreclr/vm/comsynchronizable.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,6 +714,14 @@ FCIMPL1(void, ThreadNative::Finalize, ThreadBaseObject* pThisUNSAFE)
714714
}
715715
FCIMPLEND
716716

717+
FCIMPL0(FC_BOOL_RET, ThreadNative::CatchAtSafePoint)
718+
{
719+
FCALL_CONTRACT;
720+
721+
FC_RETURN_BOOL(GetThread()->CatchAtSafePoint());
722+
}
723+
FCIMPLEND
724+
717725
// Get whether or not this is a background thread.
718726
extern "C" BOOL QCALLTYPE ThreadNative_GetIsBackground(QCall::ThreadHandle thread)
719727
{

src/coreclr/vm/comsynchronizable.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class ThreadNative
3939
ThreadAbortRequested = 128,
4040
};
4141

42-
static FCDECL0(INT32, GetOptimalMaxSpinWaitsPerSpinIteration);
43-
static FCDECL1(void, Finalize, ThreadBaseObject* pThis);
42+
static FCDECL0(INT32, GetOptimalMaxSpinWaitsPerSpinIteration);
43+
static FCDECL1(void, Finalize, ThreadBaseObject* pThis);
44+
static FCDECL0(FC_BOOL_RET, CatchAtSafePoint);
4445
};
4546

4647
extern "C" void QCALLTYPE ThreadNative_Start(QCall::ThreadHandle thread, int threadStackSize, int priority, BOOL isThreadPool, PCWSTR pThreadName);

src/coreclr/vm/ecalllist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ FCFuncEnd()
238238

239239
FCFuncStart(gThreadFuncs)
240240
FCFuncElement("InternalFinalize", ThreadNative::Finalize)
241+
FCFuncElement("CatchAtSafePoint", ThreadNative::CatchAtSafePoint)
241242
FCFuncElement("get_OptimalMaxSpinWaitsPerSpinIteration", ThreadNative::GetOptimalMaxSpinWaitsPerSpinIteration)
242243
FCFuncEnd()
243244

0 commit comments

Comments
 (0)