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
--- 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);
}
}