From: qwang12 Date: Fri, 22 Feb 2008 09:43:59 +0000 (+0000) Subject: Fix a bug reported by EDK940 "The main thread has not LeaveCriticalSection when be... X-Git-Tag: edk2-stable201903~21450 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=1710eeb85ea79ae91c9e23abc448bee553226f59 Fix a bug reported by EDK940 "The main thread has not LeaveCriticalSection when be Suspended, and the child thread will try to EnterCriticalSection, there is the confliction". git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4745 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Nt32Pkg/TimerDxe/Timer.c b/Nt32Pkg/TimerDxe/Timer.c index 97ea73345b..d9944414cf 100644 --- a/Nt32Pkg/TimerDxe/Timer.c +++ b/Nt32Pkg/TimerDxe/Timer.c @@ -115,9 +115,12 @@ Returns: if (!mCancelTimerThread) { // - // Suspend the main thread until we are done + // Suspend the main thread until we are done. + // Enter the critical section before suspending + // and leave the critical section after resuming + // to avoid deadlock between main and timer thread. // - + gWinNt->EnterCriticalSection (&mNtCriticalSection); gWinNt->SuspendThread (mNtMainThreadHandle); // @@ -127,6 +130,7 @@ Returns: // if (mCancelTimerThread) { gWinNt->ResumeThread (mNtMainThreadHandle); + gWinNt->LeaveCriticalSection (&mNtCriticalSection); gWinNt->timeKillEvent (wTimerID); mMMTimerThreadID = 0; return ; @@ -138,6 +142,7 @@ Returns: // Resume the main thread // gWinNt->ResumeThread (mNtMainThreadHandle); + gWinNt->LeaveCriticalSection (&mNtCriticalSection); // // Wait for interrupts to be enabled. @@ -151,6 +156,7 @@ Returns: // // Suspend the main thread until we are done // + gWinNt->EnterCriticalSection (&mNtCriticalSection); gWinNt->SuspendThread (mNtMainThreadHandle); mCpu->GetInterruptState (mCpu, &InterruptState); } @@ -174,9 +180,7 @@ Returns: // expired since the last call is 10,000 times the number // of ms. (or 100ns units) // - gWinNt->EnterCriticalSection (&mNtCriticalSection); CallbackFunction = mTimerNotifyFunction; - gWinNt->LeaveCriticalSection (&mNtCriticalSection); // // Only invoke the callback function if a Non-NULL handler has been @@ -194,6 +198,7 @@ Returns: // Resume the main thread // gWinNt->ResumeThread (mNtMainThreadHandle); + gWinNt->LeaveCriticalSection (&mNtCriticalSection); } else { gWinNt->timeKillEvent (wTimerID); mMMTimerThreadID = 0;