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

Commit be94fdb3 authored by John Reck's avatar John Reck
Browse files

Fix race condition in CommonPool destructor by just leaking it instead

This is a singleton that really doesn't need any at-exit cleanup.
Instead of fixing the at-exit cleanup, just don't

Test: hwuiunit
Flag: EXEMPT test app bugfix
Change-Id: I6f985ef3455bb9e48b0479d7d9b58ca22ae5cb2c
parent 067d0d32
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -52,9 +52,13 @@ CommonPool::CommonPool() : CommonPoolBase() {
    }
}

CommonPool::~CommonPool() {
    LOG_ALWAYS_FATAL("CommonPool can't be stopped");
}

CommonPool& CommonPool::instance() {
    static CommonPool pool;
    return pool;
    static CommonPool* pool = new CommonPool();
    return *pool;
}

void CommonPool::post(Task&& task) {
@@ -80,7 +84,7 @@ void CommonPool::enqueue(Task&& task) {

void CommonPool::workerLoop() {
    std::unique_lock lock(mLock);
    while (!mIsStopping) {
    while (true) {
        if (!mWorkQueue.hasWork()) {
            mWaitingThreads++;
            mCondition.wait(lock);
+1 −5
Original line number Diff line number Diff line
@@ -108,10 +108,7 @@ private:
    static CommonPool& instance();

    CommonPool();
    ~CommonPool() {
        mIsStopping = true;
        mCondition.notify_all();
    }
    ~CommonPool();

    void enqueue(Task&&);
    void doWaitForIdle();
@@ -124,7 +121,6 @@ private:
    std::condition_variable mCondition;
    int mWaitingThreads = 0;
    ArrayQueue<Task, QUEUE_SIZE> mWorkQueue;
    std::atomic_bool mIsStopping = false;
};

}  // namespace uirenderer