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 93138 72a7230e978e917e03793976ed49f07af0871dfc
parent 93137 5c35cd6f3ea46f7380f507d6d52f69c330cae5b4
child 93139 40a901a6e733adf1ac7d2869dc19fb6fe03e3b5e
push id22611
push usereakhgari@mozilla.com
push dateFri, 04 May 2012 20:23:57 +0000
treeherdermozilla-central@dc93a3faa54e [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();