diff options
author | Christopher Tate <ctate@android.com> | 2009-11-08 14:29:02 -0800 |
---|---|---|
committer | Christopher Tate <ctate@android.com> | 2009-11-08 14:29:02 -0800 |
commit | 07d69893e1677bd59a3461a0c4fcd3541563144d (patch) | |
tree | 204e09917226ac8ad93f1552749697f5b525ecb5 /libs/binder/IPCThreadState.cpp | |
parent | f84570e7afdfebb00546e87cbd54539a69aee675 (diff) | |
download | frameworks_native-07d69893e1677bd59a3461a0c4fcd3541563144d.zip frameworks_native-07d69893e1677bd59a3461a0c4fcd3541563144d.tar.gz frameworks_native-07d69893e1677bd59a3461a0c4fcd3541563144d.tar.bz2 |
Reset binder service threads' cgroup/priority after command completion
To prevent buggy command implementations from poisoning binder threads'
scheduling class & priority for future command execution, we now reset the
cgroup and thread priority to foreground/normal when a binder service thread
finishes executing the designated command.
Change-Id: Ibc0ab2485751453f6dc96fdb4eb877fd02796e3f
Diffstat (limited to 'libs/binder/IPCThreadState.cpp')
-rw-r--r-- | libs/binder/IPCThreadState.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/libs/binder/IPCThreadState.cpp b/libs/binder/IPCThreadState.cpp index e04b2bf..b2a7db8 100644 --- a/libs/binder/IPCThreadState.cpp +++ b/libs/binder/IPCThreadState.cpp @@ -426,6 +426,21 @@ void IPCThreadState::joinThreadPool(bool isMain) result = executeCommand(cmd); } + // After executing the command, ensure that the thread is returned to the + // default cgroup and priority before rejoining the pool. This is a failsafe + // in case the command implementation failed to properly restore the thread's + // scheduling parameters upon completion. + int my_id; +#ifdef HAVE_GETTID + my_id = gettid(); +#else + my_id = getpid(); +#endif + if (!set_sched_policy(my_id, SP_FOREGROUND)) { + // success; reset the priority as well + setpriority(PRIO_PROCESS, my_id, ANDROID_PRIORITY_NORMAL); + } + // Let this thread exit the thread pool if it is no longer // needed and it is not the main process thread. if(result == TIMED_OUT && !isMain) { |