summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Glenn Kasten <gkasten@google.com> 2011-06-22 17:42:23 -0700
committer Glenn Kasten <gkasten@google.com> 2011-06-22 17:45:30 -0700
commit60d47796ccfb3db3ab73017897f648678daddc83 (patch)
tree87e3bfde59e5edb34e139e15414d7e05ebab41f0
parentdf02afe8355e1e7a6f8f02549f41a166c3ee6932 (diff)
Thread ID zero for androidSetThreadSchedulingGroup
Already implemented by androidSetThreadPriority but not documented Change-Id: I85302b17092952065f3f3a4214d8d8abdd465dbd
-rw-r--r--include/utils/threads.h4
-rw-r--r--libs/utils/Threads.cpp4
2 files changed, 6 insertions, 2 deletions
diff --git a/include/utils/threads.h b/include/utils/threads.h
index 0bd69cf37796..41f67e40580c 100644
--- a/include/utils/threads.h
+++ b/include/utils/threads.h
@@ -133,13 +133,13 @@ extern pid_t androidGetTid();
// Change the scheduling group of a particular thread. The group
// should be one of the ANDROID_TGROUP constants. Returns BAD_VALUE if
// grp is out of range, else another non-zero value with errno set if
-// the operation failed.
+// the operation failed. Thread ID zero means current thread.
extern int androidSetThreadSchedulingGroup(pid_t tid, int grp);
// Change the priority AND scheduling group of a particular thread. The priority
// should be one of the ANDROID_PRIORITY constants. Returns INVALID_OPERATION
// if the priority set failed, else another value if just the group set failed;
-// in either case errno is set.
+// in either case errno is set. Thread ID zero means current thread.
extern int androidSetThreadPriority(pid_t tid, int prio);
#ifdef __cplusplus
diff --git a/libs/utils/Threads.cpp b/libs/utils/Threads.cpp
index 15bb1d22627c..71352a864fee 100644
--- a/libs/utils/Threads.cpp
+++ b/libs/utils/Threads.cpp
@@ -316,6 +316,10 @@ int androidSetThreadSchedulingGroup(pid_t tid, int grp)
#if defined(HAVE_PTHREADS)
pthread_once(&gDoSchedulingGroupOnce, checkDoSchedulingGroup);
if (gDoSchedulingGroup) {
+ // set_sched_policy does not support tid == 0
+ if (tid == 0) {
+ tid = androidGetTid();
+ }
if (set_sched_policy(tid, (grp == ANDROID_TGROUP_BG_NONINTERACT) ?
SP_BACKGROUND : SP_FOREGROUND)) {
return PERMISSION_DENIED;