Bug 1486039 - use a more-portable idiom for pausing in SpinEvent::Wait; r=aklotz
authorNathan Froyd <froydnj@mozilla.com>
Tue, 28 Aug 2018 09:27:57 -0400
changeset 488729 3568c72a41cc0ffd616ad107dace0c9253d293d7
parent 488728 793be675465bde66c019439cb1ec4dc4c4653607
child 488730 dd857ab01989843d0feae7eb4525b374e6a34439
push id9734
push usershindli@mozilla.com
push dateThu, 30 Aug 2018 12:18:07 +0000
treeherdermozilla-beta@71c71ab3afae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersaklotz
bugs1486039
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1486039 - use a more-portable idiom for pausing in SpinEvent::Wait; r=aklotz YieldProcessor is apparently defined to do the same thing on x86 as our custom macros, but includes implementations for non-x86 processors.
ipc/mscom/SpinEvent.cpp
--- a/ipc/mscom/SpinEvent.cpp
+++ b/ipc/mscom/SpinEvent.cpp
@@ -8,25 +8,16 @@
 
 #include "mozilla/ArrayUtils.h"
 #include "mozilla/Assertions.h"
 #include "mozilla/TimeStamp.h"
 #include "nsServiceManagerUtils.h"
 #include "nsString.h"
 #include "nsSystemInfo.h"
 
-// This gives us compiler intrinsics for the x86 PAUSE instruction
-#if defined(_MSC_VER)
-#include <intrin.h>
-#pragma intrinsic(_mm_pause)
-#define CPU_PAUSE() _mm_pause()
-#elif defined(__GNUC__) || defined(__clang__)
-#define CPU_PAUSE() __builtin_ia32_pause()
-#endif
-
 namespace mozilla {
 namespace mscom {
 
 static const TimeDuration kMaxSpinTime = TimeDuration::FromMilliseconds(30);
 bool SpinEvent::sIsMulticore = false;
 
 /* static */ bool
 SpinEvent::InitStatics()
@@ -63,20 +54,17 @@ SpinEvent::Wait(HANDLE aTargetThread)
     // entire time. At that point, a few extra ms isn't going to make much
     // difference to perceived responsiveness.
     TimeStamp start(TimeStamp::Now());
     while (!mDone) {
       TimeDuration elapsed(TimeStamp::Now() - start);
       if (elapsed >= kMaxSpinTime) {
         break;
       }
-      // The PAUSE instruction is a hint to the CPU that we're doing a spin
-      // loop. It is a no-op on older processors that don't support it, so
-      // it is safe to use here without any CPUID checks.
-      CPU_PAUSE();
+      YieldProcessor();
     }
     if (mDone) {
       return true;
     }
   }
 
   MOZ_ASSERT(mDoneEvent);
   HANDLE handles[] = {mDoneEvent, aTargetThread};