Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Chen Fan <chen.fan.f...@cn.fujitsu.com>
Reviewed-by: Jordan Justen <jordan.l.jus...@intel.com>
---
 EmulatorPkg/CpuRuntimeDxe/MpService.c | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/EmulatorPkg/CpuRuntimeDxe/MpService.c 
b/EmulatorPkg/CpuRuntimeDxe/MpService.c
index d79abd2..536a47f 100644
--- a/EmulatorPkg/CpuRuntimeDxe/MpService.c
+++ b/EmulatorPkg/CpuRuntimeDxe/MpService.c
@@ -437,17 +437,17 @@ CpuMpServicesStartupAllAps (
     // state 1 by 1, until the previous 1 finished its task
     // if not "SingleThread", all APs are put to ready state from the beginning
     //
+    gThread->MutexLock(ProcessorData->StateLock);
     if (ProcessorData->State == CPU_STATE_IDLE) {
-      gMPSystem.StartCount++;
-
-      gThread->MutexLock (ProcessorData->StateLock);
       ProcessorData->State = APInitialState;
       gThread->MutexUnlock (ProcessorData->StateLock);
 
+      gMPSystem.StartCount++;
       if (SingleThread) {
         APInitialState = CPU_STATE_BLOCKED;
       }
     } else {
+      gThread->MutexUnlock (ProcessorData->StateLock);
       return EFI_NOT_READY;
     }
   }
@@ -671,9 +671,12 @@ CpuMpServicesStartupThisAP (
     return EFI_INVALID_PARAMETER;
   }
 
+  gThread->MutexLock(gMPSystem.ProcessorData[ProcessorNumber].StateLock);
   if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {
+    gThread->MutexUnlock(gMPSystem.ProcessorData[ProcessorNumber].StateLock);
     return EFI_NOT_READY;
   }
+  gThread->MutexUnlock(gMPSystem.ProcessorData[ProcessorNumber].StateLock);
 
   if ((WaitEvent != NULL)  && gReadToBoot) {
     return EFI_UNSUPPORTED;
@@ -789,9 +792,12 @@ CpuMpServicesSwitchBSP (
   }
   ASSERT (Index != gMPSystem.NumberOfProcessors);
 
+  gThread->MutexLock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
   if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {
+    gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
     return EFI_NOT_READY;
   }
+  gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
 
   // Skip for now as we need switch a bunch of stack stuff around and it's 
complex
   // May not be worth it?
@@ -861,9 +867,12 @@ CpuMpServicesEnableDisableAP (
     return EFI_INVALID_PARAMETER;
   }
 
+  gThread->MutexLock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
   if (gMPSystem.ProcessorData[ProcessorNumber].State != CPU_STATE_IDLE) {
+    gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
     return EFI_UNSUPPORTED;
   }
+  gThread->MutexUnlock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
 
   if (EnableAP) {
     if ((gMPSystem.ProcessorData[ProcessorNumber].Info.StatusFlag & 
PROCESSOR_ENABLED_BIT) == 0 ) {
@@ -1019,7 +1028,9 @@ CpuCheckAllAPsStatus (
         }
       }
 
+      gThread->MutexLock (gMPSystem.ProcessorData[ProcessorNumber].StateLock);
       gMPSystem.ProcessorData[ProcessorNumber].State = CPU_STATE_IDLE;
+      gThread->MutexUnlock 
(gMPSystem.ProcessorData[ProcessorNumber].StateLock);
       gMPSystem.FinishCount++;
       break;
 
-- 
1.9.3


------------------------------------------------------------------------------
Infragistics Professional
Build stunning WinForms apps today!
Reboot your WinForms applications with our WinForms controls. 
Build a bridge from your legacy apps to the future.
http://pubads.g.doubleclick.net/gampad/clk?id=153845071&iu=/4140/ostg.clktrk
_______________________________________________
edk2-devel mailing list
edk2-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/edk2-devel

Reply via email to