Eliminate unnecessary object churn in job scheduler updating am: eafb535072

am: 84e9961a7c

Change-Id: I1df15d655f7782f3cc8ecd051ad3f0268ae8b7a7
This commit is contained in:
Christopher Tate
2016-10-06 21:24:04 +00:00
committed by android-build-merger
2 changed files with 14 additions and 1 deletions

View File

@@ -907,7 +907,11 @@ public final class JobSchedulerService extends com.android.server.SystemService
private boolean isCurrentlyActiveLocked(JobStatus job) {
for (int i=0; i<mActiveServices.size(); i++) {
JobServiceContext serviceContext = mActiveServices.get(i);
final JobStatus running = serviceContext.getRunningJob();
// The 'unsafe' direct-internal-reference running-job inspector is okay to
// use here because we are already holding the necessary lock *and* we
// immediately discard the returned object reference, if any; we return
// only a boolean state indicator to the caller.
final JobStatus running = serviceContext.getRunningJobUnsafeLocked();
if (running != null && running.matches(job.getUid(), job.getJobId())) {
return true;
}

View File

@@ -230,6 +230,15 @@ public class JobServiceContext extends IJobCallback.Stub implements ServiceConne
return job == null ? null : new JobStatus(job);
}
/**
* Internal non-cloning inspection of the currently running job, if any. The lock
* must be held when calling this *and* for the entire lifetime of using its returned
* JobStatus object!
*/
JobStatus getRunningJobUnsafeLocked() {
return mRunningJob;
}
/** Called externally when a job that was scheduled for execution should be cancelled. */
void cancelExecutingJob(int reason) {
mCallbackHandler.obtainMessage(MSG_CANCEL, reason, 0 /* unused */).sendToTarget();