bug 1249738 - make sBatteryObservers a function static r=dhylands
authorTrevor Saunders <tbsaunde@tbsaunde.org>
Fri, 19 Feb 2016 10:56:46 -0500
changeset 285824 73c742908f3fa81180be5df7d8b051260af5c5d2
parent 285823 dc371929fada4561a0bf36525a4bab5a0f3505d3
child 285825 5e27306cd8fb1e7eb0ea859691601b657ceb6727
push id30036
push usercbook@mozilla.com
push dateMon, 29 Feb 2016 10:35:59 +0000
treeherdermozilla-central@9da51cb4974e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdhylands
bugs1249738
milestone47.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
bug 1249738 - make sBatteryObservers a function static r=dhylands
hal/Hal.cpp
--- a/hal/Hal.cpp
+++ b/hal/Hal.cpp
@@ -287,17 +287,23 @@ protected:
     PROXY_IF_SANDBOXED(DisableBatteryNotifications());
   }
 
   void GetCurrentInformationInternal(BatteryInformation* aInfo) {
     PROXY_IF_SANDBOXED(GetCurrentBatteryInformation(aInfo));
   }
 };
 
-static BatteryObserversManager sBatteryObservers;
+static BatteryObserversManager&
+BatteryObservers()
+{
+  static BatteryObserversManager sBatteryObservers;
+  AssertMainThread();
+  return sBatteryObservers;
+}
 
 class NetworkObserversManager : public CachingObserversManager<NetworkInformation>
 {
 protected:
   void EnableNotifications() {
     PROXY_IF_SANDBOXED(EnableNetworkNotifications());
   }
 
@@ -343,39 +349,39 @@ protected:
 };
 
 static ScreenConfigurationObserversManager sScreenConfigurationObservers;
 
 void
 RegisterBatteryObserver(BatteryObserver* aObserver)
 {
   AssertMainThread();
-  sBatteryObservers.AddObserver(aObserver);
+  BatteryObservers().AddObserver(aObserver);
 }
 
 void
 UnregisterBatteryObserver(BatteryObserver* aObserver)
 {
   AssertMainThread();
-  sBatteryObservers.RemoveObserver(aObserver);
+  BatteryObservers().RemoveObserver(aObserver);
 }
 
 void
 GetCurrentBatteryInformation(BatteryInformation* aInfo)
 {
   AssertMainThread();
-  *aInfo = sBatteryObservers.GetCurrentInformation();
+  *aInfo = BatteryObservers().GetCurrentInformation();
 }
 
 void
 NotifyBatteryChange(const BatteryInformation& aInfo)
 {
   AssertMainThread();
-  sBatteryObservers.CacheInformation(aInfo);
-  sBatteryObservers.BroadcastCachedInformation();
+  BatteryObservers().CacheInformation(aInfo);
+  BatteryObservers().BroadcastCachedInformation();
 }
 
 bool GetScreenEnabled()
 {
   AssertMainThread();
   RETURN_PROXY_IF_SANDBOXED(GetScreenEnabled(), false);
 }