diff options
Diffstat (limited to 'libs/utils/Threads.cpp')
| -rw-r--r-- | libs/utils/Threads.cpp | 46 | 
1 files changed, 38 insertions, 8 deletions
| diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index 2b1f49044d34..f6c55e4d89de 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -21,6 +21,7 @@  #include <utils/Log.h>  #include <cutils/sched_policy.h> +#include <cutils/properties.h>  #include <stdio.h>  #include <stdlib.h> @@ -57,13 +58,27 @@ using namespace android;  // ----------------------------------------------------------------------------  /* - * Create and run a new thead. + * Create and run a new thread.   *   * We create it "detached", so it cleans up after itself.   */  typedef void* (*android_pthread_entry)(void*); +static pthread_once_t gDoSchedulingGroupOnce = PTHREAD_ONCE_INIT; +static bool gDoSchedulingGroup = true; + +static void checkDoSchedulingGroup(void) { +    char buf[PROPERTY_VALUE_MAX]; +    int len = property_get("debug.sys.noschedgroups", buf, ""); +    if (len > 0) { +        int temp; +        if (sscanf(buf, "%d", &temp) == 1) { +            gDoSchedulingGroup = temp == 0; +        } +    } +} +  struct thread_data_t {      thread_func_t   entryFunction;      void*           userData; @@ -79,6 +94,15 @@ struct thread_data_t {          char * name = t->threadName;          delete t;          setpriority(PRIO_PROCESS, 0, prio); +        pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); +        if (gDoSchedulingGroup) { +            if (prio >= ANDROID_PRIORITY_BACKGROUND) { +                set_sched_policy(androidGetTid(), SP_BACKGROUND); +            } else { +                set_sched_policy(androidGetTid(), SP_FOREGROUND); +            } +        } +                  if (name) {  #if defined(HAVE_PRCTL)              // Mac OS doesn't have this, and we build libutil for the host too @@ -287,9 +311,12 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp)      }  #if defined(HAVE_PTHREADS) -    if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? -                                      SP_BACKGROUND : SP_FOREGROUND)) { -        return PERMISSION_DENIED; +    pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); +    if (gDoSchedulingGroup) { +        if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ? +                                          SP_BACKGROUND : SP_FOREGROUND)) { +            return PERMISSION_DENIED; +        }      }  #endif @@ -303,10 +330,13 @@ int androidSetThreadPriority(pid_t tid, int pri)  #if defined(HAVE_PTHREADS)      int lasterr = 0; -    if (pri >= ANDROID_PRIORITY_BACKGROUND) { -        rc = set_sched_policy(tid, SP_BACKGROUND); -    } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { -        rc = set_sched_policy(tid, SP_FOREGROUND); +    pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup); +    if (gDoSchedulingGroup) { +        if (pri >= ANDROID_PRIORITY_BACKGROUND) { +            rc = set_sched_policy(tid, SP_BACKGROUND); +        } else if (getpriority(PRIO_PROCESS, tid) >= ANDROID_PRIORITY_BACKGROUND) { +            rc = set_sched_policy(tid, SP_FOREGROUND); +        }      }      if (rc) { | 
