Merge mozilla-central to autoland. a=merge CLOSED TREE
authorOana Pop Rus <opoprus@mozilla.com>
Mon, 04 Feb 2019 11:45:35 +0200
changeset 456605 13a4db7bd6f5091d8c4bb4465ddeadb08e27ddd5
parent 456604 9dc88ca66bfa8bf16f1cfd5af000bf06ff75245d (current diff)
parent 456600 1206de2a542c7af235552f78ce015177ec3d4ec0 (diff)
child 456606 53951b4b6ac20a1e7543a37d867bae2641e7926f
push id35496
push userbtara@mozilla.com
push dateMon, 04 Feb 2019 17:36:40 +0000
treeherdermozilla-central@be1beccfb86d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmerge
milestone67.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
Merge mozilla-central to autoland. a=merge CLOSED TREE
--- a/gfx/vr/gfxVRExternal.cpp
+++ b/gfx/vr/gfxVRExternal.cpp
@@ -437,51 +437,41 @@ VRSystemManagerExternal::VRSystemManager
   mShmemFD = 0;
 #elif defined(XP_WIN)
   mShmemFile = NULL;
 #elif defined(MOZ_WIDGET_ANDROID)
   mExternalStructFailed = false;
   mEnumerationCompleted = false;
 #endif
   mDoShutdown = false;
-
-#if defined(XP_WIN)
-  mMutex = CreateMutex(
-    NULL,                   // default security descriptor
-    false,                  // mutex not owned
-    TEXT("mozilla::vr::ShmemMutex"));  // object name
-
-  if (mMutex == NULL) {
-    nsAutoCString msg;
-    msg.AppendPrintf("VRSystemManagerExternal CreateMutex error \"%lu\".",
-                      GetLastError());
-    NS_WARNING(msg.get());
-    MOZ_ASSERT(false);
-    return;
-  }
-  // At xpcshell extension tests, it creates multiple VRSystemManagerExternal instances
-  // in plug-contrainer.exe. It causes GetLastError() return `ERROR_ALREADY_EXISTS`.
-  // However, even though `ERROR_ALREADY_EXISTS`, it still returns the same mutex handle.
-  //
-  // https://docs.microsoft.com/en-us/windows/desktop/api/synchapi/nf-synchapi-createmutexa
-  MOZ_ASSERT(GetLastError() == 0 || GetLastError() == ERROR_ALREADY_EXISTS);
-#endif  // defined(XP_WIN)
 }
 
-VRSystemManagerExternal::~VRSystemManagerExternal() {
-  CloseShmem();
-#if defined(XP_WIN)
-  if (mMutex) {
-    CloseHandle(mMutex);
-    mMutex = NULL;
-  }
-#endif
-}
+VRSystemManagerExternal::~VRSystemManagerExternal() { CloseShmem(); }
 
 void VRSystemManagerExternal::OpenShmem() {
+#if defined(XP_WIN)
+  if (!mMutex) {
+     mMutex = CreateMutex(
+        NULL,                   // default security descriptor
+        false,                  // mutex not owned
+        TEXT("mozilla::vr::ShmemMutex"));  // object name
+
+    if (mMutex == NULL) {
+      nsAutoCString msg("VRService CreateMutex error \"%lu\".",
+                        GetLastError());
+      NS_WARNING(msg.get());
+      MOZ_ASSERT(false);
+      return;
+    }
+    else if (GetLastError() == ERROR_ALREADY_EXISTS) {
+      NS_WARNING("CreateMutex opened an existing mutex.");
+    }
+  }
+#endif  // defined(XP_WIN)
+
   if (mExternalShmem) {
     return;
 #if defined(MOZ_WIDGET_ANDROID)
   } else if (mExternalStructFailed) {
     return;
 #endif  // defined(MOZ_WIDGET_ANDROID)
   }
 
@@ -575,16 +565,22 @@ void VRSystemManagerExternal::OpenShmem(
 
 void VRSystemManagerExternal::CheckForShutdown() {
   if (mDoShutdown) {
     Shutdown();
   }
 }
 
 void VRSystemManagerExternal::CloseShmem() {
+#if defined(XP_WIN)
+  if (mMutex) {
+    CloseHandle(mMutex);
+    mMutex = NULL;
+  }
+#endif
 #if !defined(MOZ_WIDGET_ANDROID)
   if (mSameProcess) {
     return;
   }
 #endif
 #if defined(XP_MACOSX)
   if (mExternalShmem) {
     munmap((void*)mExternalShmem, sizeof(VRExternalShmem));
--- a/gfx/vr/gfxVRMutex.h
+++ b/gfx/vr/gfxVRMutex.h
@@ -13,19 +13,18 @@ namespace gfx {
 #if defined(XP_WIN)
 class WaitForMutex
 {
 public:
   explicit WaitForMutex(HANDLE handle)
     : mHandle(handle)
     , mStatus(false) {
 
-    MOZ_ASSERT(mHandle);
+    DWORD dwWaitResult;
 
-    DWORD dwWaitResult;
     dwWaitResult = WaitForSingleObject(
         mHandle,    // handle to mutex
         INFINITE);  // no time-out interval
 
     switch (dwWaitResult) {
       // The thread got ownership of the mutex
       case WAIT_OBJECT_0:
         mStatus = true;
@@ -39,20 +38,16 @@ public:
       default:
         mStatus = false;
         break;
     }
   }
 
   ~WaitForMutex() {
     if (mHandle && !ReleaseMutex(mHandle)) {
-      nsAutoCString msg;
-      msg.AppendPrintf("WaitForMutex %d ReleaseMutex error \"%lu\".",
-                        mHandle, GetLastError());
-      NS_WARNING(msg.get());
       MOZ_ASSERT(false, "Failed to release mutex.");
     }
   }
 
   bool GetStatus() {
     return mStatus;
   }
 
--- a/gfx/vr/service/VRService.cpp
+++ b/gfx/vr/service/VRService.cpp
@@ -98,34 +98,16 @@ void VRService::Refresh() {
   }
 
   if (mAPIShmem->state.displayState.shutdown) {
     Stop();
   }
 }
 
 void VRService::Start() {
-#if defined(XP_WIN)
-  if (!mMutex) {
-     mMutex = OpenMutex(
-        MUTEX_ALL_ACCESS,       // request full access
-        false,                  // handle not inheritable
-        TEXT("mozilla::vr::ShmemMutex"));  // object name
-
-    if (mMutex == NULL) {
-      nsAutoCString msg;
-      msg.AppendPrintf("VRService OpenMutex error \"%lu\".",
-                       GetLastError());
-      NS_WARNING(msg.get());
-      MOZ_ASSERT(false);
-    }
-    MOZ_ASSERT(GetLastError() == 0);
-  }
-#endif
-
   if (!mServiceThread) {
     /**
      * We must ensure that any time the service is re-started, that
      * the VRSystemState is reset, including mSystemState.enumerationCompleted
      * This must happen before VRService::Start returns to the caller, in order
      * to prevent the WebVR/WebXR promises from being resolved before the
      * enumeration has been completed.
      */
@@ -179,16 +161,33 @@ void VRService::Stop() {
   if (mMutex) {
     CloseHandle(mMutex);
   }
 #endif
   mSession = nullptr;
 }
 
 bool VRService::InitShmem() {
+#if defined(XP_WIN)
+  if (!mMutex) {
+     mMutex = OpenMutex(
+        MUTEX_ALL_ACCESS,       // request full access
+        false,                  // handle not inheritable
+        TEXT("mozilla::vr::ShmemMutex"));  // object name
+
+    if (mMutex == NULL) {
+      nsAutoCString msg("VRService OpenMutex error \"%lu\".",
+                        GetLastError());
+      NS_WARNING(msg.get());
+      MOZ_ASSERT(false);
+      return false;
+    }
+  }
+#endif
+
   if (!mVRProcessEnabled) {
     return true;
   }
 
 #if defined(XP_WIN)
   const char* kShmemName = "moz.gecko.vr_ext.0.0.1";
   base::ProcessHandle targetHandle = 0;