// Invoke all the registered GC callouts of the given kind. The condemned generation of the current collection // is passed along to the callouts. void RestrictedCallouts::InvokeGcCallouts(GcRestrictedCalloutKind eKind, UInt32 uiCondemnedGeneration) { ASSERT(eKind < GCRC_Count); // It is illegal for any of the callouts to trigger a GC. Thread * pThread = ThreadStore::GetCurrentThread(); pThread->SetDoNotTriggerGc(); // Due to the above we have better suppress GC stress. bool fGcStressWasSuppressed = pThread->IsSuppressGcStressSet(); if (!fGcStressWasSuppressed) pThread->SetSuppressGcStress(); GcRestrictedCallout * pCurrCallout = s_rgGcRestrictedCallouts[eKind]; while (pCurrCallout) { // Make the callout. ((GcRestrictedCallbackFunction)pCurrCallout->m_pCalloutMethod)(uiCondemnedGeneration); pCurrCallout = pCurrCallout->m_pNext; } // Revert GC stress mode if we changed it. if (!fGcStressWasSuppressed) pThread->ClearSuppressGcStress(); pThread->ClearDoNotTriggerGc(); }
// Invoke all the registered ref counted handle callouts for the given object extracted from the handle. The // result is the union of the results for all the handlers that matched the object type (i.e. if one of them // returned true the overall result is true otherwise false is returned (which includes the case where no // handlers matched)). Since there should be no other side-effects of the callout, the invocations cease as // soon as a handler returns true. bool RestrictedCallouts::InvokeRefCountedHandleCallbacks(Object * pObject) { bool fResult = false; // It is illegal for any of the callouts to trigger a GC. Thread * pThread = ThreadStore::GetCurrentThread(); pThread->SetDoNotTriggerGc(); // Due to the above we have better suppress GC stress. bool fGcStressWasSuppressed = pThread->IsSuppressGcStressSet(); if (!fGcStressWasSuppressed) pThread->SetSuppressGcStress(); HandleTableRestrictedCallout * pCurrCallout = s_pHandleTableRestrictedCallouts; while (pCurrCallout) { if (pObject->get_SafeEEType() == pCurrCallout->m_pTypeFilter) { // Make the callout. Return true to our caller as soon as we see a true result here. if (((HandleTableRestrictedCallbackFunction)pCurrCallout->m_pCalloutMethod)(pObject)) { fResult = true; goto Done; } } pCurrCallout = pCurrCallout->m_pNext; } Done: // Revert GC stress mode if we changed it. if (!fGcStressWasSuppressed) pThread->ClearSuppressGcStress(); pThread->ClearDoNotTriggerGc(); return fResult; }