summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKevin F. Haggerty <haggertk@lineageos.org>2021-10-05 06:49:47 -0600
committerKevin F. Haggerty <haggertk@lineageos.org>2021-10-05 06:49:47 -0600
commitb992512ecec436ecf6f5441095152bd160111b36 (patch)
tree1e22ad105e1119eabdf0a2e83ea7145aa807ee8f
parentd6357492605501092ebf0c13082088fa4b5f1ac8 (diff)
parentfa34315231b6fa66593a9d2165bcc14751c2b5d2 (diff)
Merge tag 'android-11.0.0_r46' into staging/lineage-18.1_merge-android-11.0.0_r46
Android 11.0.0 Release 46 (RQ3A.211001.001) * tag 'android-11.0.0_r46': aaudio: unlock when joining the timestamp thread aaudio: prevent deadlock when stop() calls disconnect() Change-Id: I35dc0fbc07ef3e0594c11d218e35e064c7af8ffa
-rw-r--r--services/oboeservice/AAudioServiceStreamBase.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/services/oboeservice/AAudioServiceStreamBase.cpp b/services/oboeservice/AAudioServiceStreamBase.cpp
index 663dae29cc..30deb5df9c 100644
--- a/services/oboeservice/AAudioServiceStreamBase.cpp
+++ b/services/oboeservice/AAudioServiceStreamBase.cpp
@@ -293,10 +293,6 @@ aaudio_result_t AAudioServiceStreamBase::pause_l() {
.set(AMEDIAMETRICS_PROP_STATUS, (int32_t)result)
.record(); });
- // Send it now because the timestamp gets rounded up when stopStream() is called below.
- // Also we don't need the timestamps while we are shutting down.
- sendCurrentTimestamp();
-
result = stopTimestampThread();
if (result != AAUDIO_OK) {
disconnect_l();
@@ -342,10 +338,12 @@ aaudio_result_t AAudioServiceStreamBase::stop_l() {
setState(AAUDIO_STREAM_STATE_STOPPING);
- // Send it now because the timestamp gets rounded up when stopStream() is called below.
- // Also we don't need the timestamps while we are shutting down.
- sendCurrentTimestamp(); // warning - this calls a virtual function
+ // Temporarily unlock because we are joining the timestamp thread and it may try
+ // to acquire mLock.
+ mLock.unlock();
result = stopTimestampThread();
+ mLock.lock();
+
if (result != AAUDIO_OK) {
disconnect_l();
return result;
@@ -410,10 +408,11 @@ void AAudioServiceStreamBase::run() {
timestampScheduler.start(AudioClock::getNanoseconds());
int64_t nextTime = timestampScheduler.nextAbsoluteTime();
int32_t loopCount = 0;
+ aaudio_result_t result = AAUDIO_OK;
while(mThreadEnabled.load()) {
loopCount++;
if (AudioClock::getNanoseconds() >= nextTime) {
- aaudio_result_t result = sendCurrentTimestamp();
+ result = sendCurrentTimestamp();
if (result != AAUDIO_OK) {
ALOGE("%s() timestamp thread got result = %d", __func__, result);
break;
@@ -425,6 +424,11 @@ void AAudioServiceStreamBase::run() {
AudioClock::sleepUntilNanoTime(nextTime);
}
}
+ // This was moved from the calls in stop_l() and pause_l(), which could cause a deadlock
+ // if it resulted in a call to disconnect.
+ if (result == AAUDIO_OK) {
+ (void) sendCurrentTimestamp();
+ }
ALOGD("%s() %s exiting after %d loops <<<<<<<<<<<<<< TIMESTAMPS",
__func__, getTypeText(), loopCount);
}