Backed out changeset 12b2328eedd1 (bug 1523926) as requested by daoshengmu. a=backout
authorOana Pop Rus <opoprus@mozilla.com>
Mon, 04 Feb 2019 11:29:45 +0200
changeset 456621 1206de2a542c7af235552f78ce015177ec3d4ec0
parent 456616 965b28c159d63ef17357eeac75a0257277f9a3f4
child 456622 13a4db7bd6f5091d8c4bb4465ddeadb08e27ddd5
child 456659 bfa8e495f538885abc2dc0a46a2a570eb536bcf3
push id77372
push useropoprus@mozilla.com
push dateMon, 04 Feb 2019 09:45:28 +0000
treeherderautoland@13a4db7bd6f5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbackout
bugs1523926
milestone67.0a1
backs out12b2328eedd1c1d8863a4ee2c18591eaf2a522dd
first release with
nightly linux32
1206de2a542c / 67.0a1 / 20190204092937 / files
nightly linux64
1206de2a542c / 67.0a1 / 20190204092937 / files
nightly mac
1206de2a542c / 67.0a1 / 20190204092937 / files
nightly win32
1206de2a542c / 67.0a1 / 20190204092937 / files
nightly win64
1206de2a542c / 67.0a1 / 20190204092937 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Backed out changeset 12b2328eedd1 (bug 1523926) as requested by daoshengmu. a=backout
gfx/vr/gfxVRExternal.cpp
gfx/vr/gfxVRMutex.h
gfx/vr/service/VRService.cpp
--- 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;