Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8041e31 authored by Phil Burk's avatar Phil Burk Committed by Automerger Merge Worker
Browse files

aaudio: prevent deadlock when stop() calls disconnect() am: 9dd928e1

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/av/+/14937759

Change-Id: Ib1cac04e28f1627fd296841298fae89b6c877625
parents 6484574c 9dd928e1
Loading
Loading
Loading
Loading
+7 −8
Original line number Diff line number Diff line
@@ -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,9 +338,6 @@ 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
    result = stopTimestampThread();
    if (result != AAUDIO_OK) {
        disconnect_l();
@@ -410,10 +403,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 +419,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);
}