summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorZach Jang <zachjang@google.com>2015-10-27 02:33:01 +0000
committerandroid-build-merger <android-build-merger@google.com>2015-10-27 02:33:01 +0000
commit8c5b71ce473517ea1270f6467fa518274bd54b35 (patch)
tree1aa3f492b81e9b7834babf095188ce9eb4439621 /services
parent1fcbd9b0e973d662ed566967af71c8f5b2383320 (diff)
parent6919fbe40d92af432d3b72ad36e0697654f8146c (diff)
downloadframeworks_av-8c5b71ce473517ea1270f6467fa518274bd54b35.zip
frameworks_av-8c5b71ce473517ea1270f6467fa518274bd54b35.tar.gz
frameworks_av-8c5b71ce473517ea1270f6467fa518274bd54b35.tar.bz2
Merge "Revert "Revert "AudioPolicyService: fix race in AudioCommandThread""" into mnc-dev
am: 6919fbe40d * commit '6919fbe40d92af432d3b72ad36e0697654f8146c': Revert "Revert "AudioPolicyService: fix race in AudioCommandThread""
Diffstat (limited to 'services')
-rw-r--r--services/audiopolicy/service/AudioPolicyService.cpp24
1 files changed, 16 insertions, 8 deletions
diff --git a/services/audiopolicy/service/AudioPolicyService.cpp b/services/audiopolicy/service/AudioPolicyService.cpp
index eefff3d..c77cc45 100644
--- a/services/audiopolicy/service/AudioPolicyService.cpp
+++ b/services/audiopolicy/service/AudioPolicyService.cpp
@@ -577,22 +577,28 @@ bool AudioPolicyService::AudioCommandThread::threadLoop()
}
}
waitTime = INT64_MAX;
+ // release mLock before releasing strong reference on the service as
+ // AudioPolicyService destructor calls AudioCommandThread::exit() which
+ // acquires mLock.
+ mLock.unlock();
+ svc.clear();
+ mLock.lock();
} else {
waitTime = mAudioCommands[0]->mTime - curTime;
break;
}
}
- // release mLock before releasing strong reference on the service as
- // AudioPolicyService destructor calls AudioCommandThread::exit() which acquires mLock.
- mLock.unlock();
- svc.clear();
- mLock.lock();
- if (!exitPending() && (mAudioCommands.isEmpty() || waitTime != INT64_MAX)) {
- // release delayed commands wake lock
+
+ // release delayed commands wake lock if the queue is empty
+ if (mAudioCommands.isEmpty()) {
release_wake_lock(mName.string());
+ }
+
+ // At this stage we have either an empty command queue or the first command in the queue
+ // has a finite delay. So unless we are exiting it is safe to wait.
+ if (!exitPending()) {
ALOGV("AudioCommandThread() going to sleep");
mWaitWorkCV.waitRelative(mLock, waitTime);
- ALOGV("AudioCommandThread() waking up");
}
}
// release delayed commands wake lock before quitting
@@ -1003,6 +1009,8 @@ void AudioPolicyService::AudioCommandThread::exit()
requestExit();
mWaitWorkCV.signal();
}
+ // Note that we can call it from the thread loop if all other references have been released
+ // but it will safely return WOULD_BLOCK in this case
requestExitAndWait();
}