Bug 751423 - Wait for IO thread to finish setup. r=cjones
authorSteven Lee <slee@mozilla.com>
Fri, 04 May 2012 15:16:27 +0800
changeset 93116 72a7230e978e917e03793976ed49f07af0871dfc
parent 93115 5c35cd6f3ea46f7380f507d6d52f69c330cae5b4
child 93117 40a901a6e733adf1ac7d2869dc19fb6fe03e3b5e
push id8985
push userkchen@mozilla.com
push dateFri, 04 May 2012 07:16:51 +0000
treeherdermozilla-inbound@72a7230e978e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscjones
bugs751423
milestone15.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 751423 - Wait for IO thread to finish setup. r=cjones
hal/gonk/GonkSwitch.cpp
--- a/hal/gonk/GonkSwitch.cpp
+++ b/hal/gonk/GonkSwitch.cpp
@@ -4,16 +4,17 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <android/log.h>
 #include <sysutils/NetlinkEvent.h>
 
 #include "base/message_loop.h"
 
 #include "Hal.h"
+#include "mozilla/Monitor.h"
 #include "nsXULAppAPI.h"
 #include "UeventPoller.h"
 
 using namespace mozilla::hal;
 
 #define LOG(args...)  __android_log_print(ANDROID_LOG_INFO, "GonkSwitch" , ## args) 
 
 namespace mozilla {
@@ -149,28 +150,37 @@ ReleaseResourceIfNeed()
   if (sSwitchObserver->GetEnableCount() == 0) {
     UnregisterUeventListener(sSwitchObserver);
     delete sSwitchObserver;
     sSwitchObserver = NULL;
   }
 }
 
 static void
-EnableSwitchNotificationsIOThread(SwitchDevice aDevice)
+EnableSwitchNotificationsIOThread(SwitchDevice aDevice, Monitor *aMonitor)
 {
   InitializeResourceIfNeed();
   sSwitchObserver->EnableSwitch(aDevice);
+  {
+    MonitorAutoLock lock(*aMonitor);
+    lock.Notify();
+  }
 }
 
 void
 EnableSwitchNotifications(SwitchDevice aDevice)
 {
-  XRE_GetIOMessageLoop()->PostTask(
-      FROM_HERE,
-      NewRunnableFunction(EnableSwitchNotificationsIOThread, aDevice));
+  Monitor monitor("EnableSwitch.monitor");
+  {
+    MonitorAutoLock lock(monitor);
+    XRE_GetIOMessageLoop()->PostTask(
+        FROM_HERE,
+        NewRunnableFunction(EnableSwitchNotificationsIOThread, aDevice, &monitor));
+    lock.Wait();
+  }
 }
 
 static void
 DisableSwitchNotificationsIOThread(SwitchDevice aDevice)
 {
   MOZ_ASSERT(sSwitchObserver->GetEnableCount());
   sSwitchObserver->DisableSwitch(aDevice);
   ReleaseResourceIfNeed();