- PowerOfTwoCounter = GetPowerOfTwo32 (GetApicTimerInitCount ());\r
- while (((UINT32)(GetApicTimerCurrentCount () - Ticks) & PowerOfTwoCounter) == 0) {\r
- CpuPause ();\r
- }\r
+ StartTick = GetApicTimerCurrentCount ();\r
+ do {\r
+ //\r
+ // Wait until time out by Delay value\r
+ //\r
+ do {\r
+ CpuPause ();\r
+ //\r
+ // Get Ticks from Start to Current.\r
+ //\r
+ Ticks = StartTick - GetApicTimerCurrentCount ();\r
+ //\r
+ // Ticks < 0 means Timer wrap-arounds happens.\r
+ //\r
+ if (Ticks < 0) {\r
+ Ticks += InitCount;\r
+ }\r
+ } while ((UINT32)Ticks < Delay);\r
+\r
+ //\r
+ // Update StartTick and Delay for next delay slot\r
+ //\r
+ StartTick -= (StartTick > Delay) ? Delay : (Delay - InitCount);\r
+ Delay = InitCount / 2;\r
+ } while (Times-- > 0);\r