static bool IsPreemptiveGCDisabled(Thread * pThread);
static void EnablePreemptiveGC(Thread * pThread);
static void DisablePreemptiveGC(Thread * pThread);
+ static bool TrapReturningThreads();
static gc_alloc_context * GetAllocContext(Thread * pThread);
static bool CatchAtSafePoint(Thread * pThread);
}
// if we're waiting for gc to finish, we should block immediately
- if (!g_TrapReturningThreads)
+ if (!GCToEEInterface::TrapReturningThreads())
{
if (g_num_processors > 1)
{
// is in a tight loop. If the thread has high priority, the perf is going to be very BAD.
if (pCurThread)
{
- if (bToggleGC || g_TrapReturningThreads)
+ if (bToggleGC || GCToEEInterface::TrapReturningThreads())
{
#ifdef _DEBUG
// In debug builds, all enter_spin_lock operations go through this code. If a GC has
}
}
}
- else if (g_TrapReturningThreads)
+ else if (GCToEEInterface::TrapReturningThreads())
{
g_theGCHeap->WaitUntilGCComplete();
}
g_theGCToCLR->DisablePreemptiveGC(pThread);
}
+ALWAYS_INLINE bool GCToEEInterface::TrapReturningThreads()
+{
+ assert(g_theGCToCLR != nullptr);
+ return g_theGCToCLR->TrapReturningThreads();
+}
+
ALWAYS_INLINE gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
{
assert(g_theGCToCLR != nullptr);
// to threads returning to cooperative mode is down after gc.
// In other words, if the sequence in GCHeap::RestartEE changes,
// the condition here may have to change as well.
- return g_TrapReturningThreads == 0;
+ return !GCToEEInterface::TrapReturningThreads();
}
public:
//return TRUE if GC actually happens, otherwise FALSE
virtual
void DisablePreemptiveGC(Thread * pThread) = 0;
+ // Returns whether or not a thread suspension is pending.
+ virtual
+ bool TrapReturningThreads() = 0;
+
// Retrieves the alloc context associated with a given thread.
virtual
gc_alloc_context * GetAllocContext(Thread * pThread) = 0;
pThread->DisablePreemptiveGC();
}
+bool GCToEEInterface::TrapReturningThreads()
+{
+ return !!g_TrapReturningThreads;
+}
+
gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
{
return pThread->GetAllocContext();
pThread->DisablePreemptiveGC();
}
+bool GCToEEInterface::TrapReturningThreads()
+{
+ WRAPPER_NO_CONTRACT;
+ return !!g_TrapReturningThreads;
+}
+
struct BackgroundThreadStubArgs
{
Thread* thread;
bool IsPreemptiveGCDisabled(Thread * pThread);
void EnablePreemptiveGC(Thread * pThread);
void DisablePreemptiveGC(Thread * pThread);
+ bool TrapReturningThreads();
gc_alloc_context * GetAllocContext(Thread * pThread);
bool CatchAtSafePoint(Thread * pThread);
void GcEnumAllocContexts(enum_alloc_context_func* fn, void* param);