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

Commit 7fce0a53 authored by Haynes Mathew George's avatar Haynes Mathew George Committed by Gerrit - the friendly Code Review server
Browse files

audio: Fix three-way deadlock

This is a fix for a deadlock in the audio HAL
involving three threads. Heres the deadlock sequence.

As part of closing all compress streams during SSR,
Thread1 takes out->lock, adev->lock and releases
out->lock when waiting on a condition variable
in stop_compress_output_l

Concurrently, Thread2 calls out_set_parameter on
the same output take out->lock and is blocked
trying to acquire adev->lock

Meanwhile Thread3 (offload_thread_loop) tries to
acquire out->lock (in order to signal Thread1).

But Thread3 is blocked since Thread2 has already
taken out->lock. This is a deadlock.

CRs-Fixed: 1028547

Change-Id: Ie8a8ff5e4d65c5a73641f925a46d03235d1a0f50
parent 3cc657ab
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -2185,6 +2185,9 @@ static int out_standby(struct audio_stream *stream)
        if (adev->adm_deregister_stream)
            adev->adm_deregister_stream(adev->adm_data, out->handle);

        if (is_offload_usecase(out->usecase))
            stop_compressed_output_l(out);

        pthread_mutex_lock(&adev->lock);
        out->standby = true;
        if (!is_offload_usecase(out->usecase)) {
@@ -2194,7 +2197,6 @@ static int out_standby(struct audio_stream *stream)
            }
        } else {
            ALOGD("copl(%p):standby", out);
            stop_compressed_output_l(out);
            out->send_next_track_params = false;
            out->is_compr_metadata_avail = false;
            out->gapless_mdata.encoder_delay = 0;