Bug 803471 - Part 1a - Enable Binder ThreadPool. r=mwu, a=leo+
authorSotaro Ikeda <sikeda@mozilla.com>
Fri, 08 Mar 2013 14:43:32 -0500
changeset 118716 d031aae8da48f0720c21056ae3b50d318678a1f8
parent 118715 2944420ff12bd52e1ddcb35eafbd7463b586daca
child 118717 aaca95d502f5566a3dda62d95a7defdd087fb9a4
push id540
push userryanvm@gmail.com
push dateTue, 12 Mar 2013 01:17:01 +0000
reviewersmwu, leo
bugs803471
milestone18.0
Bug 803471 - Part 1a - Enable Binder ThreadPool. r=mwu, a=leo+
b2g/app/nsBrowserApp.cpp
ipc/app/MozillaRuntimeMain.cpp
--- a/b2g/app/nsBrowserApp.cpp
+++ b/b2g/app/nsBrowserApp.cpp
@@ -32,16 +32,20 @@
 #ifdef MOZ_WIDGET_GONK
 #include "BootAnimation.h"
 #endif
 
 #include "BinaryPath.h"
 
 #include "nsXPCOMPrivate.h" // for MAXPATHLEN and XPCOM_DLL
 
+#ifdef MOZ_WIDGET_GONK
+# include <binder/ProcessState.h>
+#endif
+
 #include "mozilla/Telemetry.h"
 
 static void Output(const char *fmt, ... )
 {
   va_list ap;
   va_start(ap, fmt);
 
 #if defined(XP_WIN) && !MOZ_WINCONSOLE
@@ -163,16 +167,24 @@ static int do_main(int argc, char* argv[
 
   return XRE_main(argc, argv, &sAppData, 0);
 }
 
 int main(int argc, char* argv[])
 {
   char exePath[MAXPATHLEN];
 
+#ifdef MOZ_WIDGET_GONK
+  // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
+  // receive binder calls, though not necessary to send binder calls.
+  // ProcessState::Self() also needs to be called once on the main thread to
+  // register the main thread with the binder driver.
+  android::ProcessState::self()->startThreadPool();
+#endif
+
   nsresult rv = mozilla::BinaryPath::Get(argv[0], exePath);
   if (NS_FAILED(rv)) {
     Output("Couldn't calculate the application directory.\n");
     return 255;
   }
 
   char *lastSlash = strrchr(exePath, XPCOM_FILE_PATH_SEPARATOR[0]);
   if (!lastSlash || ((lastSlash - exePath) + sizeof(XPCOM_DLL) + 1 > MAXPATHLEN))
--- a/ipc/app/MozillaRuntimeMain.cpp
+++ b/ipc/app/MozillaRuntimeMain.cpp
@@ -17,19 +17,31 @@
 // we want a wmain entry point
 // but we don't want its DLL load protection, because we'll handle it here
 #define XRE_DONT_PROTECT_DLL_LOAD
 #include "nsWindowsWMain.cpp"
 
 #include "nsSetDllDirectory.h"
 #endif
 
+#ifdef MOZ_WIDGET_GONK
+# include <binder/ProcessState.h>
+#endif
+
 int
 main(int argc, char* argv[])
 {
+#ifdef MOZ_WIDGET_GONK
+    // This creates a ThreadPool for binder ipc. A ThreadPool is necessary to
+    // receive binder calls, though not necessary to send binder calls.
+    // ProcessState::Self() also needs to be called once on the main thread to
+    // register the main thread with the binder driver.
+    android::ProcessState::self()->startThreadPool();
+#endif
+
 #if defined(XP_WIN) && defined(DEBUG_bent)
     MessageBox(NULL, L"Hi", L"Hi", MB_OK);
 #endif
 
     // Check for the absolute minimum number of args we need to move
     // forward here. We expect the last arg to be the child process type.
     if (argc < 1)
       return 1;