Bug 993737 - Only fire shutdown notifications on main thread. r=gsvelto
authorDave Hylands <dhylands@mozilla.com>
Wed, 30 Apr 2014 17:20:30 -0700
changeset 181588 aed338f33904cff21b0e030af31db3204196e88d
parent 181587 76eede9ccce5e2c2be7699542233bf211201e37a
child 181589 90d43f11b2b8b956993bbddc027c944ed4f1a5a8
push id272
push userpvanderbeken@mozilla.com
push dateMon, 05 May 2014 16:31:18 +0000
reviewersgsvelto
bugs993737
milestone32.0a1
Bug 993737 - Only fire shutdown notifications on main thread. r=gsvelto
hal/linux/LinuxPower.cpp
--- a/hal/linux/LinuxPower.cpp
+++ b/hal/linux/LinuxPower.cpp
@@ -4,37 +4,42 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include "Hal.h"
 
 #include <unistd.h>
 #include <sys/reboot.h>
 #include "nsIObserverService.h"
 #include "mozilla/Services.h"
+#include "MainThreadUtils.h"
 
 namespace mozilla {
 namespace hal_impl {
 
 void
 Reboot()
 {
-  nsCOMPtr<nsIObserverService> obsServ = services::GetObserverService();
-  if (obsServ) {
-    obsServ->NotifyObservers(nullptr, "system-reboot", nullptr);
+  if (NS_IsMainThread()) {
+    nsCOMPtr<nsIObserverService> obsServ = services::GetObserverService();
+    if (obsServ) {
+      obsServ->NotifyObservers(nullptr, "system-reboot", nullptr);
+    }
   }
   sync();
   reboot(RB_AUTOBOOT);
 }
 
 void
 PowerOff()
 {
-  nsCOMPtr<nsIObserverService> obsServ = services::GetObserverService();
-  if (obsServ) {
-    obsServ->NotifyObservers(nullptr, "system-power-off", nullptr);
+  if (NS_IsMainThread()) {
+    nsCOMPtr<nsIObserverService> obsServ = services::GetObserverService();
+    if (obsServ) {
+      obsServ->NotifyObservers(nullptr, "system-power-off", nullptr);
+    }
   }
   sync();
   reboot(RB_POWER_OFF);
 }
 
 // Structure to specify how watchdog pthread is going to work.
 typedef struct watchdogParam
 {