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

Commit f803533c authored by Weilin Xu's avatar Weilin Xu Committed by Android (Google) Code Review
Browse files

Merge "Fix timeout issue for bcradio worker thread" into main

parents 16c0974b 82f17d9e
Loading
Loading
Loading
Loading
+3 −0
Original line number Diff line number Diff line
@@ -86,4 +86,7 @@ cc_test {
    ],
    static_libs: ["android.hardware.broadcastradio@common-utils-lib"],
    test_suites: ["general-tests"],
    shared_libs: [
        "libbase",
    ],
}
+4 −1
Original line number Diff line number Diff line
@@ -69,8 +69,11 @@ void WorkerThread::cancelAll() {
}

void WorkerThread::threadLoop() {
    while (!mIsTerminating) {
    while (true) {
        unique_lock<mutex> lk(mMut);
        if (mIsTerminating) {
            return;
        }
        if (mTasks.empty()) {
            mCond.wait(lk);
            continue;
+5 −3
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@
#include <queue>
#include <thread>

#include <android-base/thread_annotations.h>

namespace android {

class WorkerThread {
@@ -40,11 +42,11 @@ class WorkerThread {
    };
    friend bool operator<(const Task& lhs, const Task& rhs);

    std::atomic<bool> mIsTerminating;
    std::mutex mMut;
    std::condition_variable mCond;
    bool mIsTerminating GUARDED_BY(mMut);
    std::condition_variable mCond GUARDED_BY(mMut);
    std::thread mThread;
    std::priority_queue<Task> mTasks;
    std::priority_queue<Task> mTasks GUARDED_BY(mMut);

    void threadLoop();
};