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; }
DWORD WINAPI APIThreadStress::StartThread(void *arg) { APIThreadStress *pThis = (APIThreadStress *) arg; ClrFlsSetValue(TlsIdx_StressThread, pThis); EX_TRY { // Perform initial synchronization WaitForSingleObjectEx(pThis->m_syncEvent, INFINITE, FALSE); InterlockedIncrement(&pThis->m_runCount); LOG((LF_SYNC, LL_INFO100, "Stressing operation on thread %d\n", GetCurrentThreadId())); ((APIThreadStress *)arg)->Invoke(); LOG((LF_SYNC, LL_INFO100, "End stress operation on thread %d\n", GetCurrentThreadId())); if (InterlockedDecrement(&pThis->m_runCount) == 0) ::SetEvent(pThis->m_syncEvent); } EX_CATCH { LOG((LF_SYNC, LL_ERROR, "Exception during stress operation on thread %d\n", GetCurrentThreadId())); } EX_END_CATCH(SwallowAllExceptions); return 0; }
void SetDisplayingAssertDlg(BOOL value) { STATIC_CONTRACT_NOTHROW; STATIC_CONTRACT_GC_NOTRIGGER; STATIC_CONTRACT_DEBUG_ONLY; ClrFlsSetValue(TlsIdx_AssertDlgStatus, (LPVOID)(size_t)value); }
LogEnv::~LogEnv() { ClrFlsSetValue(TlsIdx_JitLogEnv, next); // pop me off the environment stack }
LogEnv::LogEnv(ICorJitInfo* aCompHnd) : compHnd(aCompHnd), compiler(0) { next = (LogEnv*) ClrFlsGetValue(TlsIdx_JitLogEnv); ClrFlsSetValue(TlsIdx_JitLogEnv, this); }