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

Commit 0821db29 authored by Andy Hung's avatar Andy Hung
Browse files

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 ba04dbe7.

Test: Verbose log on StreamManager.cpp, run SoundPool CTS tests.
Bug: 182923919
Change-Id: Iae794bc957869426a4e1e27cd3c088aa9dd83208
parent d96c8193
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -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();