void DecCantAllocCount() { size_t count = 0; if (ClrFlsCheckValue(TlsIdx_CantAllocCount, (LPVOID *)&count)) { if (count > 0) { ClrFlsSetValue(TlsIdx_CantAllocCount, (LPVOID)(count-1)); return; } } PVOID fiberId = ClrTeb::GetFiberPtrId(); for (int i = 0; i < MaxCantAllocThreadNum; i ++) { if (g_CantAllocThreads[i].m_fiberId == fiberId) { _ASSERTE (g_CantAllocThreads[i].m_CantCount > 0); g_CantAllocThreads[i].m_CantCount --; if (g_CantAllocThreads[i].m_CantCount == 0) { g_CantAllocThreads[i].m_fiberId = NULL; } return; } } _ASSERTE (g_CantAllocStressLogCount > 0); InterlockedDecrement (&g_CantAllocStressLogCount); return; }
void IncCantAllocCount() { size_t count = 0; if (ClrFlsCheckValue(TlsIdx_CantAllocCount, (LPVOID *)&count)) { _ASSERTE (count >= 0); ClrFlsSetValue(TlsIdx_CantAllocCount, (LPVOID)(count+1)); return; } PVOID fiberId = ClrTeb::GetFiberPtrId(); for (int i = 0; i < MaxCantAllocThreadNum; i ++) { if (g_CantAllocThreads[i].m_fiberId == fiberId) { g_CantAllocThreads[i].m_CantCount ++; return; } } for (int i = 0; i < MaxCantAllocThreadNum; i ++) { if (g_CantAllocThreads[i].m_fiberId == NULL) { if (InterlockedCompareExchangeT(&g_CantAllocThreads[i].m_fiberId, fiberId, NULL) == NULL) { _ASSERTE(g_CantAllocThreads[i].m_CantCount == 0); g_CantAllocThreads[i].m_CantCount = 1; return; } } } count = InterlockedIncrement (&g_CantAllocStressLogCount); _ASSERTE (count >= 1); return; }
// Whether this thread is already displaying an assert dialog. BOOL IsDisplayingAssertDlg() { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; STATIC_CONTRACT_DEBUG_ONLY; size_t flag = 0; if (ClrFlsCheckValue(TlsIdx_AssertDlgStatus, (LPVOID *)&flag)) { return (flag != 0); } return FALSE; }
// for stress log the rule is more restrict, we have to check the global counter too BOOL IsInCantAllocStressLogRegion() { size_t count = 0; if (ClrFlsCheckValue(TlsIdx_CantAllocCount, (LPVOID *)&count)) { if (count > 0) { return true; } } PVOID fiberId = ClrTeb::GetFiberPtrId(); for (int i = 0; i < MaxCantAllocThreadNum; i ++) { if (g_CantAllocThreads[i].m_fiberId == fiberId) { _ASSERTE (g_CantAllocThreads[i].m_CantCount > 0); return true; } } return g_CantAllocStressLogCount > 0; }