Bug 951120 - Don't process native events on the main thread during xpcom shutdown in metro widget. r=bbondy, a=metro-only
authorJim Mathies <jmathies@mozilla.com>
Mon, 27 Jan 2014 09:09:33 -0600
changeset 176093 7e64908ef411c6385b03e27dbd8dcb24ff80ca46
parent 176092 82bc631a9e53a14d8abf4e40d4db7508d6e7e279
child 176094 5b9c5ed94b04258f1be088609c144abb5e5826ba
push id445
push userffxbld
push dateMon, 10 Mar 2014 22:05:19 +0000
treeherdermozilla-release@dc38b741b04e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbbondy, metro-only
bugs951120
milestone28.0a2
Bug 951120 - Don't process native events on the main thread during xpcom shutdown in metro widget. r=bbondy, a=metro-only
widget/windows/winrt/MetroApp.cpp
widget/windows/winrt/MetroApp.h
widget/windows/winrt/MetroAppShell.cpp
--- a/widget/windows/winrt/MetroApp.cpp
+++ b/widget/windows/winrt/MetroApp.cpp
@@ -37,16 +37,17 @@ extern PRLogModuleInfo* gWindowsLog;
 
 namespace mozilla {
 namespace widget {
 namespace winrt {
 
 ComPtr<FrameworkView> sFrameworkView;
 ComPtr<MetroApp> sMetroApp;
 ComPtr<ICoreApplication> sCoreApp;
+bool MetroApp::sGeckoShuttingDown = false;
 
 ////////////////////////////////////////////////////
 // IFrameworkViewSource impl.
 
 // Called after CoreApplication::Run(app)
 HRESULT
 MetroApp::CreateView(ABI::Windows::ApplicationModel::Core::IFrameworkView **aViewProvider)
 {
@@ -104,16 +105,18 @@ MetroApp::ShutdownXPCOM()
     sCoreApp->remove_Suspending(mSuspendEvent);
     sCoreApp->remove_Resuming(mResumeEvent);
   }
 
   if (sFrameworkView) {
     sFrameworkView->ShutdownXPCOM();
   }
 
+  MetroApp::sGeckoShuttingDown = true;
+
   // Shut down xpcom
   XRE_metroShutdown();
 
   // Unhook this thread from the profiler
   profiler_unregister_thread();
 }
 
 // Request a shutdown of the application
--- a/widget/windows/winrt/MetroApp.h
+++ b/widget/windows/winrt/MetroApp.h
@@ -41,16 +41,18 @@ public:
 
   // nsIWinMetroUtils tile related async callbacks
   HRESULT OnAsyncTileCreated(ABI::Windows::Foundation::IAsyncOperation<bool>* aOperation, AsyncStatus aStatus);
 
   void Run();
   void CoreExit();
 
   void ShutdownXPCOM();
+  // Set when gecko enters xpcom shutdown.
+  static bool sGeckoShuttingDown;
 
   // Shared pointers between framework and widget
   static void SetBaseWidget(MetroWidget* aPtr);
   static void PostSuspendResumeProcessNotification(bool aIsSuspend);
   static void PostSleepWakeNotification(bool aIsSuspend);
 
 private:
   EventRegistrationToken mSuspendEvent;
--- a/widget/windows/winrt/MetroAppShell.cpp
+++ b/widget/windows/winrt/MetroAppShell.cpp
@@ -319,18 +319,18 @@ MetroAppShell::InputEventsDispatched()
 {
   sBlockNativeEvents = false;
 }
 
 // static
 void
 MetroAppShell::DispatchAllGeckoEvents()
 {
-  // Only do this if requested
-  if (!sShouldPurgeThreadQueue) {
+  // Only do this if requested and when we're not shutting down
+  if (!sShouldPurgeThreadQueue || MetroApp::sGeckoShuttingDown) {
     return;
   }
 
   NS_ASSERTION(NS_IsMainThread(), "DispatchAllGeckoEvents should be called on the main thread");
 
   sShouldPurgeThreadQueue = false;
   sPurgeThreadQueueStart = TimeStamp::Now();
 
@@ -409,16 +409,25 @@ MetroAppShell::ProcessNextNativeEvent(bo
   }
   return ProcessOneNativeEventIfPresent();
 }
 
 void
 MetroAppShell::NativeCallback()
 {
   NS_ASSERTION(NS_IsMainThread(), "Native callbacks must be on the metro main thread");
+
+  // We shouldn't process native events during xpcom shutdown - this can
+  // trigger unexpected xpcom event dispatching for the main thread when
+  // the thread manager is in the process of shutting down non-main threads,
+  // resulting in shutdown hangs.
+  if (MetroApp::sGeckoShuttingDown) {
+    return;
+  }
+
   NativeEventCallback();
 }
 
 // static
 LRESULT CALLBACK
 MetroAppShell::EventWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
 {
   if (uMsg == sAppShellGeckoMsgId) {