SoundPool: Avoid busy waiting during stream restart

A stream on the restart queue can cause the StreamManager to
busy-wait.  This was introduced by a fix
commit ba04dbe773.

Test: Verbose log on StreamManager.cpp, run SoundPool CTS tests.
Bug: 182923919
Change-Id: Iae794bc957869426a4e1e27cd3c088aa9dd83208
This commit is contained in:
Andy Hung
2021-03-15 19:01:51 -07:00
parent d96c8193e2
commit 0821db29bf

View File

@@ -358,14 +358,14 @@ void StreamManager::addToActiveQueue_l(Stream *stream) {
void StreamManager::run(int32_t id)
{
ALOGV("%s(%d) entering", __func__, id);
int64_t waitTimeNs = kWaitTimeBeforeCloseNs;
int64_t waitTimeNs = 0; // on thread start, mRestartStreams can be non-empty.
std::unique_lock lock(mStreamManagerLock);
while (!mQuit) {
if (mRestartStreams.empty()) { // on thread start, mRestartStreams can be non-empty.
if (waitTimeNs > 0) {
mStreamManagerCondition.wait_for(
lock, std::chrono::duration<int64_t, std::nano>(waitTimeNs));
}
ALOGV("%s(%d) awake", __func__, id);
ALOGV("%s(%d) awake lock waitTimeNs:%lld", __func__, id, (long long)waitTimeNs);
sanityCheckQueue_l();