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

Commit 7ddf1046 authored by Patrick Rohr's avatar Patrick Rohr
Browse files

clean up notification of FilterCallbackScheduler when stopping

I am adding two minor tweaks to change
I2b9d45fa7df3f2490893cc24d98c0e0baaaf0c2c which notifies the condition
variable when trying to join the thread:
    1. the mutex lock does not need to be held to notify the condition
    variable.
    2. adding isRunning check to existing if condition in
    threadLoopOnce to condense the code.

Bug: 183057734
Test: atest android.media.tv.tuner.cts
Change-Id: Ia35e645bddd5005218e8e017a22b87b349997658
parent d22db0a7
Loading
Loading
Loading
Loading
+5 −10
Original line number Diff line number Diff line
@@ -88,12 +88,9 @@ void FilterCallbackScheduler::start() {
}

void FilterCallbackScheduler::stop() {
    {
        std::unique_lock<std::mutex> lock(mLock);
    mIsRunning = false;
        mCv.notify_all();
    }
    if (mCallbackThread.joinable()) {
        mCv.notify_all();
        mCallbackThread.join();
    }
}
@@ -117,13 +114,11 @@ void FilterCallbackScheduler::threadLoopOnce() {
        // okay to send data.
        mCv.wait(lock);
    }
    if (!mIsRunning) {
        lock.unlock();
        return;
    }

    // condition_variable wait locks mutex on timeout / notify
    if (!mCallbackBuffer.empty()) {
    // Note: if stop() has been called in the meantime, do not send more filter
    // events.
    if (mIsRunning && !mCallbackBuffer.empty()) {
        if (mCallback) {
            mCallback->onFilterEvent(mCallbackBuffer);
        }