aaudio: prevent deadlock when stop() calls disconnect()
Move all calls to send the timestamp into the one timestamp thread.
There was a clear code path that could lead to a deadlock.
If the call to get the timestamp from the HAL returned
an unexpected error code then it would call disconnect().
If that happened below the call to stop() then the
deadlock would occur.
The sequence of calls was AAudioServiceStreamBase::stop()
which locked mLock,
then called AAudioServiceStreamBase::stop_l(),
which called AAudioServiceStreamBase:sendCurrentTimeStamp(),
which called AAudioServiceStreamMMAP::getFreeRunningPosition(),
which called disconnect(),
which locked mLock AGAIN.
It is not clear what would trigger the error return
from the HAL but a routing change may be involved.
The bug was discovered during stress tests and we do not
have a clear repro case.
Test: atest CtsNativeMediaAAudioTestCases
(cherry picked from commit 45da1b7e3231bf3475cb9ca1a2243a27355c0466)
(cherry picked from commit 9dd928e100d38c42f68c04c01f09fa8c8cb606d3)
1 file changed