Bug 1350688 - Use a thread safe way to get the CPU count in the SpinEvent ctor. r=aklotz draft
authorAndrew McCreight <continuation@gmail.com>
Sun, 26 Mar 2017 06:56:01 -0700
changeset 551475 dcc319ec9c16b6065f189d30228ea94a529ab39b
parent 551474 00c0b47e3c88b464855c5cb70970462fd5a3d635
child 551803 51f0dfa4deffe48e6bac071137d59598699fe41c
push id51058
push userbmo:continuation@gmail.com
push dateSun, 26 Mar 2017 16:21:58 +0000
reviewersaklotz
bugs1350688
milestone55.0a1
Bug 1350688 - Use a thread safe way to get the CPU count in the SpinEvent ctor. r=aklotz Initializing nsSystemInfo can't be done off the main thread on Windows, and we can't guarantee that it has been initialized before calling this code. MozReview-Commit-ID: DRNCrakNMmH
ipc/mscom/SpinEvent.cpp
--- a/ipc/mscom/SpinEvent.cpp
+++ b/ipc/mscom/SpinEvent.cpp
@@ -23,25 +23,19 @@
 
 namespace mozilla {
 namespace mscom {
 
 SpinEvent::SpinEvent()
   : mDone(false)
 {
   static const bool sIsMulticore = []() {
-    nsCOMPtr<nsIPropertyBag2> infoService = do_GetService(NS_SYSTEMINFO_CONTRACTID);
-    if (!infoService) {
-      return false;
-    }
-
-    uint32_t cpuCount;
-    nsresult rv = infoService->GetPropertyAsUint32(NS_LITERAL_STRING("cpucount"),
-                                                   &cpuCount);
-    return NS_SUCCEEDED(rv) && cpuCount > 1;
+    SYSTEM_INFO sysInfo;
+    ::GetSystemInfo(&sysInfo);
+    return sysInfo.dwNumberOfProcessors > 1;
   }();
 
   if (!sIsMulticore) {
     mDoneEvent.own(::CreateEventW(nullptr, FALSE, FALSE, nullptr));
     MOZ_ASSERT(mDoneEvent);
   }
 }