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

Commit d13ce18c authored by Android Build Merger (Role)'s avatar Android Build Merger (Role) Committed by Android (Google) Code Review
Browse files

Merge "Merge "Fix NativeCallbackThread race condition." into oc-mr1-dev am:...

Merge "Merge "Fix NativeCallbackThread race condition." into oc-mr1-dev am: 63643ced am: 7bf620f4"
parents 4db66b66 ca48ea02
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -274,6 +274,21 @@ public class RadioTunerTest {
        verify(mCallback, timeout(kTuneCallbackTimeoutMs)).onProgramInfoChanged(any());
    }

    @Test
    public void testStepLoop() {
        openTuner();

        for (int i = 0; i < 10; i++) {
            Log.d(TAG, "step loop iteration " + (i + 1));

            int ret = mRadioTuner.step(RadioTuner.DIRECTION_DOWN, true);
            assertEquals(RadioManager.STATUS_OK, ret);
            verify(mCallback, timeout(kTuneCallbackTimeoutMs)).onProgramInfoChanged(any());

            resetCallback();
        }
    }

    @Test
    public void testTuneAndGetPI() {
        openTuner();
+10 −4
Original line number Diff line number Diff line
@@ -48,15 +48,19 @@ void NativeCallbackThread::threadLoop() {
        return;
    }

    while (!mExiting) {
        ALOGV("Waiting for task...");
    while (true) {
        Task task;
        {
            unique_lock<mutex> lk(mQueueMutex);

            if (mExiting) break;
            if (mQueue.empty()) {
                ALOGV("Waiting for task...");
                mQueueCond.wait(lk);
                if (mExiting) break;

                if (mQueue.empty()) continue;
            }

            task = mQueue.front();
            mQueue.pop();
        }
@@ -74,6 +78,7 @@ void NativeCallbackThread::threadLoop() {
    ALOGE_IF(res != JNI_OK, "Couldn't detach thread");

    ALOGV("Native callback thread %p finished", this);
    ALOGD_IF(!mQueue.empty(), "Skipped execution of %zu tasks", mQueue.size());
}

void NativeCallbackThread::enqueue(const Task &task) {
@@ -84,6 +89,7 @@ void NativeCallbackThread::enqueue(const Task &task) {
        return;
    }

    ALOGV("Adding task to the queue...");
    mQueue.push(task);
    mQueueCond.notify_one();
}