diff options
| author | 2010-09-09 15:50:18 -0700 | |
|---|---|---|
| committer | 2010-09-09 22:12:25 -0700 | |
| commit | 9c82c48d52edb722cc3991ef3c0ad5f07aa12fea (patch) | |
| tree | a79d00805e2f5e317f8259425e15edae96f340bf /libs/utils/Threads.cpp | |
| parent | ad70b5ab4b2c304f3b178e446a4a1760aaf87c28 (diff) | |
Always set the scheduling group when starting a new thread.
Change-Id: Ia33acf13fc3752707f3819928c36315e223fa1bd
Diffstat (limited to 'libs/utils/Threads.cpp')
| -rw-r--r-- | libs/utils/Threads.cpp | 39 | 
1 files changed, 23 insertions, 16 deletions
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp index e5ece8e8a2..f6c55e4d89 100644 --- a/libs/utils/Threads.cpp +++ b/libs/utils/Threads.cpp @@ -65,6 +65,20 @@ using namespace android;  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; @@ -80,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 @@ -281,22 +304,6 @@ pid_t androidGetTid()  #endif  } -#if defined(HAVE_PTHREADS) -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; -        } -    } -} -#endif -  int androidSetThreadSchedulingGroup(pid_t tid, int grp)  {      if (grp > ANDROID_TGROUP_MAX || grp < 0) {   |