From 7e63789a0e0689d940609b1daceebc1bc08dcbef Mon Sep 17 00:00:00 2001 From: San Mehat Date: Thu, 6 Aug 2009 13:19:19 -0700 Subject: [PATCH] android: cgroups: Don't switch threads >= nice 10 when moving all threads to default Signed-off-by: San Mehat --- core/jni/android_util_Process.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/core/jni/android_util_Process.cpp b/core/jni/android_util_Process.cpp index aee0ed7f42f88..98fe0e654e14d 100644 --- a/core/jni/android_util_Process.cpp +++ b/core/jni/android_util_Process.cpp @@ -251,10 +251,27 @@ void android_os_Process_setProcessGroup(JNIEnv* env, jobject clazz, int pid, jin } while ((de = readdir(d))) { + int t_pid; + int t_pri; + if (de->d_name[0] == '.') continue; + t_pid = atoi(de->d_name); - if (add_pid_to_cgroup(atoi(de->d_name), grp)) { + if (!t_pid) { + LOGE("Error getting pid for '%s'\n", de->d_name); + continue; + } + + t_pri = getpriority(PRIO_PROCESS, t_pid); + + if (grp == ANDROID_TGROUP_DEFAULT && + t_pri >= ANDROID_PRIORITY_BACKGROUND) { + // This task wants to stay at background + continue; + } + + if (add_pid_to_cgroup(t_pid, grp)) { // If the thread exited on us, ignore it and keep going if (errno != ESRCH && errno != ENOENT) { signalExceptionForGroupError(env, clazz, errno);