Bug 882552 - Change Binder Thread's default priority to 0. r=mwu, r=jlebar, a=leo+
authorSotaro Ikeda <sikeda@mozilla.com>
Thu, 20 Jun 2013 12:51:19 -0400
changeset 119617 a34f6d62cb05
parent 119616 f8148cef6556
child 119619 7772c18ffdec
push id900
push userryanvm@gmail.com
push date2013-06-21 00:28 +0000
reviewersmwu, jlebar, leo
bugs882552
milestone18.1
Bug 882552 - Change Binder Thread's default priority to 0. r=mwu, r=jlebar, a=leo+
ipc/app/MozillaRuntimeMain.cpp
--- a/ipc/app/MozillaRuntimeMain.cpp
+++ b/ipc/app/MozillaRuntimeMain.cpp
@@ -18,28 +18,53 @@
 // 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 <sys/time.h>
+# include <sys/resource.h> 
+
 # include <binder/ProcessState.h>
+
+# ifdef LOGE_IF
+#  undef LOGE_IF
+# endif
+
+# include <android/log.h>
+# define LOGE_IF(cond, ...) \
+     ( (CONDITION(cond)) \
+     ? ((void)__android_log_print(ANDROID_LOG_ERROR, \
+       "Gecko:MozillaRntimeMain", __VA_ARGS__)) \
+     : (void)0 )
+
 #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.
+
+    // Change thread priority to 0 only during calling ProcessState::self().
+    // The priority is registered to binder driver and used for default Binder
+    // Thread's priority. 
+    // To change the process's priority to small value need's root permission.
+    int curPrio = getpriority(PRIO_PROCESS, 0);
+    int err = setpriority(PRIO_PROCESS, 0, 0);
+    MOZ_ASSERT(!err);
+    LOGE_IF(err, "setpriority failed. Current process needs root permission.");
     android::ProcessState::self()->startThreadPool();
+    setpriority(PRIO_PROCESS, 0, curPrio);
 #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.