summaryrefslogtreecommitdiff
path: root/src/gc/sample
diff options
context:
space:
mode:
authorDavid Mason <davmason@microsoft.com>2018-03-13 01:24:20 -0700
committerGitHub <noreply@github.com>2018-03-13 01:24:20 -0700
commit8edb3ef2529cc0beb0c034482fdb32fa4c95c606 (patch)
tree369d8ecf4ca45f42341fc50b750ca7fe13086834 /src/gc/sample
parent0c4344f5a999d817b431b9e3934600ccb97d0e4b (diff)
downloadcoreclr-8edb3ef2529cc0beb0c034482fdb32fa4c95c606.tar.gz
coreclr-8edb3ef2529cc0beb0c034482fdb32fa4c95c606.tar.bz2
coreclr-8edb3ef2529cc0beb0c034482fdb32fa4c95c606.zip
[local gc] refactor apis for threading and suspension to avoid redundant calls in to the runtime (#16765)
* [Local GC] Refactor calls involving thread modes, suspension, and alloc contexts to always operate on current thread * BOOL -> bool for enable/disable preemptive routines, also remove an unused call to GetThread * avoid one indirection by having GCToEEInterface::EnablePreemptiveGC return a bool indicating whether the mode was changed * Callback on IGCHeap for the runtime to notify the GC when it is trapping threads * use g_fSuspensionPending instead of GCToEEInterface::CatchAtSafePoint for allow_fgc * Remove CatchAtSafePoint * Remove GetThread from WaitLongerNoInstru * code review feedback * code review feedback * change BOOL to bool
Diffstat (limited to 'src/gc/sample')
-rw-r--r--src/gc/sample/gcenv.ee.cpp45
-rw-r--r--src/gc/sample/gcenv.h7
2 files changed, 22 insertions, 30 deletions
diff --git a/src/gc/sample/gcenv.ee.cpp b/src/gc/sample/gcenv.ee.cpp
index 3d0303205e..996701e74a 100644
--- a/src/gc/sample/gcenv.ee.cpp
+++ b/src/gc/sample/gcenv.ee.cpp
@@ -11,8 +11,6 @@
MethodTable * g_pFreeObjectMethodTable;
-int32_t g_TrapReturningThreads;
-
EEConfig * g_pConfig;
gc_alloc_context g_global_alloc_context;
@@ -88,18 +86,14 @@ uint32_t CLREventStatic::Wait(uint32_t dwMilliseconds, bool bAlertable)
if (NULL != pCurThread)
{
- if (GCToEEInterface::IsPreemptiveGCDisabled(pCurThread))
- {
- GCToEEInterface::EnablePreemptiveGC(pCurThread);
- disablePreemptive = true;
- }
+ disablePreemptive = GCToEEInterface::EnablePreemptiveGC();
}
result = WaitForSingleObjectEx(m_hEvent, dwMilliseconds, bAlertable);
if (disablePreemptive)
{
- GCToEEInterface::DisablePreemptiveGC(pCurThread);
+ GCToEEInterface::DisablePreemptiveGC();
}
}
@@ -175,18 +169,32 @@ bool GCToEEInterface::RefCountedHandleCallbacks(Object * pObject)
return false;
}
-bool GCToEEInterface::IsPreemptiveGCDisabled(Thread * pThread)
+bool GCToEEInterface::IsPreemptiveGCDisabled()
{
+ Thread* pThread = ::GetThread();
return pThread->PreemptiveGCDisabled();
}
-void GCToEEInterface::EnablePreemptiveGC(Thread * pThread)
+bool GCToEEInterface::EnablePreemptiveGC()
{
- return pThread->EnablePreemptiveGC();
+ bool bToggleGC = false;
+ Thread* pThread = ::GetThread();
+
+ if (pThread)
+ {
+ bToggleGC = !!pThread->PreemptiveGCDisabled();
+ if (bToggleGC)
+ {
+ pThread->EnablePreemptiveGC();
+ }
+ }
+
+ return bToggleGC;
}
-void GCToEEInterface::DisablePreemptiveGC(Thread * pThread)
+void GCToEEInterface::DisablePreemptiveGC()
{
+ Thread* pThread = ::GetThread();
pThread->DisablePreemptiveGC();
}
@@ -195,21 +203,12 @@ Thread* GCToEEInterface::GetThread()
return ::GetThread();
}
-bool GCToEEInterface::TrapReturningThreads()
-{
- return !!g_TrapReturningThreads;
-}
-
-gc_alloc_context * GCToEEInterface::GetAllocContext(Thread * pThread)
+gc_alloc_context * GCToEEInterface::GetAllocContext()
{
+ Thread* pThread = ::GetThread();
return pThread->GetAllocContext();
}
-bool GCToEEInterface::CatchAtSafePoint(Thread * pThread)
-{
- return pThread->CatchAtSafePoint();
-}
-
void GCToEEInterface::GcEnumAllocContexts (enum_alloc_context_func* fn, void* param)
{
Thread * pThread = NULL;
diff --git a/src/gc/sample/gcenv.h b/src/gc/sample/gcenv.h
index 54b596e141..012ab44482 100644
--- a/src/gc/sample/gcenv.h
+++ b/src/gc/sample/gcenv.h
@@ -124,13 +124,6 @@ public:
void SetGCSpecial(bool fGCSpecial)
{
}
-
- bool CatchAtSafePoint()
- {
- // This is only called by the GC on a background GC worker thread that's explicitly interested in letting
- // a foreground GC proceed at that point. So it's always safe to return true.
- return true;
- }
};
Thread * GetThread();