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

Commit 81fe612e authored by Christian Bejram's avatar Christian Bejram Committed by Android (Google) Code Review
Browse files

Merge "AudioPolicyService: fix race in AudioCommandThread" into mnc-dev

parents 32ba6ec7 74ce88ff
Loading
Loading
Loading
Loading
+16 −8
Original line number Diff line number Diff line
@@ -577,22 +577,28 @@ bool AudioPolicyService::AudioCommandThread::threadLoop()
                    }
                }
                waitTime = INT64_MAX;
                // release mLock before releasing strong reference on the service as
                // AudioPolicyService destructor calls AudioCommandThread::exit() which
                // acquires mLock.
                mLock.unlock();
                svc.clear();
                mLock.lock();
            } else {
                waitTime = mAudioCommands[0]->mTime - curTime;
                break;
            }
        }
        // release mLock before releasing strong reference on the service as
        // AudioPolicyService destructor calls AudioCommandThread::exit() which acquires mLock.
        mLock.unlock();
        svc.clear();
        mLock.lock();
        if (!exitPending() && (mAudioCommands.isEmpty() || waitTime != INT64_MAX)) {
            // release delayed commands wake lock

        // release delayed commands wake lock if the queue is empty
        if (mAudioCommands.isEmpty()) {
            release_wake_lock(mName.string());
        }

        // At this stage we have either an empty command queue or the first command in the queue
        // has a finite delay. So unless we are exiting it is safe to wait.
        if (!exitPending()) {
            ALOGV("AudioCommandThread() going to sleep");
            mWaitWorkCV.waitRelative(mLock, waitTime);
            ALOGV("AudioCommandThread() waking up");
        }
    }
    // release delayed commands wake lock before quitting
@@ -1003,6 +1009,8 @@ void AudioPolicyService::AudioCommandThread::exit()
        requestExit();
        mWaitWorkCV.signal();
    }
    // Note that we can call it from the thread loop if all other references have been released
    // but it will safely return WOULD_BLOCK in this case
    requestExitAndWait();
}