void COptex::Enter() { // Spin, trying to get the optex if (TryEnter()) return; // We got it, return // We couldn't get the optex, wait for it. DWORD dwThreadId = GetCurrentThreadId(); if (InterlockedIncrement(&m_psi->m_lLockCount) == 1) { // Optex is unowned, let this thread own it once m_psi->m_dwThreadId = dwThreadId; m_psi->m_lRecurseCount = 1; } else { if (m_psi->m_dwThreadId == dwThreadId) { // If optex is owned by this thread, own it again m_psi->m_lRecurseCount++; } else { // Optex is owned by another thread, wait for it WaitForSingleObject(m_hevt, INFINITE); // Optex is unowned, let this thread own it once m_psi->m_dwThreadId = dwThreadId; m_psi->m_lRecurseCount = 1; } } }
///////////////////////////////////////////////////////////////////////////////////// // Name : Enter // Full name : CWinCS::Enter // Access : public // Brief : 获取CS控制权 // Parameter : // Return : void // Notes : void CWinCS::Enter() { #if(_WIN32_WINNT >= 0x0403) TryEnter(); #else ::EnterCriticalSection(&m_cWinCS); #endif } // End of function Enter(...