Merge "Fix thread priority after boosting." into nyc-dev-plus-aosp
This commit is contained in:
@@ -640,30 +640,41 @@ public final class ActivityManagerService extends ActivityManagerNative
|
|||||||
return mShowDialogs && !mSleeping && !mShuttingDown;
|
return mShowDialogs && !mSleeping && !mShuttingDown;
|
||||||
}
|
}
|
||||||
|
|
||||||
// it's a semaphore; boost when 0->1, reset when 1->0
|
private static final class PriorityState {
|
||||||
static ThreadLocal<Integer> sIsBoosted = new ThreadLocal<Integer>() {
|
// Acts as counter for number of synchronized region that needs to acquire 'this' as a lock
|
||||||
@Override protected Integer initialValue() {
|
// the current thread is currently in. When it drops down to zero, we will no longer boost
|
||||||
return 0;
|
// the thread's priority.
|
||||||
|
private int regionCounter = 0;
|
||||||
|
|
||||||
|
// The thread's previous priority before boosting.
|
||||||
|
private int prevPriority = Integer.MIN_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
static ThreadLocal<PriorityState> sThreadPriorityState = new ThreadLocal<PriorityState>() {
|
||||||
|
@Override protected PriorityState initialValue() {
|
||||||
|
return new PriorityState();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
static void boostPriorityForLockedSection() {
|
static void boostPriorityForLockedSection() {
|
||||||
if (sIsBoosted.get() == 0) {
|
int tid = Process.myTid();
|
||||||
// boost to prio 118 while holding a global lock
|
int prevPriority = Process.getThreadPriority(tid);
|
||||||
Process.setThreadPriority(Process.myTid(), -2);
|
PriorityState state = sThreadPriorityState.get();
|
||||||
//Log.e(TAG, "PRIORITY BOOST: set priority on TID " + Process.myTid());
|
if (state.regionCounter == 0 && prevPriority > -2) {
|
||||||
|
state.prevPriority = prevPriority;
|
||||||
|
Process.setThreadPriority(tid, -2);
|
||||||
}
|
}
|
||||||
int cur = sIsBoosted.get();
|
state.regionCounter++;
|
||||||
sIsBoosted.set(cur + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void resetPriorityAfterLockedSection() {
|
static void resetPriorityAfterLockedSection() {
|
||||||
sIsBoosted.set(sIsBoosted.get() - 1);
|
PriorityState state = sThreadPriorityState.get();
|
||||||
if (sIsBoosted.get() == 0) {
|
state.regionCounter--;
|
||||||
//Log.e(TAG, "PRIORITY BOOST: reset priority on TID " + Process.myTid());
|
if (state.regionCounter == 0 && state.prevPriority > -2) {
|
||||||
Process.setThreadPriority(Process.myTid(), 0);
|
Process.setThreadPriority(Process.myTid(), state.prevPriority);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PendingAssistExtras extends Binder implements Runnable {
|
public class PendingAssistExtras extends Binder implements Runnable {
|
||||||
public final ActivityRecord activity;
|
public final ActivityRecord activity;
|
||||||
public final Bundle extras;
|
public final Bundle extras;
|
||||||
|
|||||||
Reference in New Issue
Block a user