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

Commit 298a1467 authored by Tom Cherry's avatar Tom Cherry
Browse files

Check for spurious wake ups

Condition::wait() can spuriously wake up, so we must guard it with
another check to ensure that a given wake was truly due to having
been signaled.

Bug: 34592766
Test: Boot bullhead
Change-Id: Iaa5a0ca6186aea50c51e2c402ef95d7ba861be92
parent 3e640036
Loading
Loading
Loading
Loading
+3 −1
Original line number Diff line number Diff line
@@ -685,7 +685,9 @@ void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
    SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
    AutoMutex _lock(mSyncMutex);
    mRenderThread.queue(&syncTask);
    while (!syncTask.hasRun()) {
        mSyncCondition.wait(mSyncMutex);
    }
    return retval;
}

+1 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@ namespace renderthread {
void SignalingRenderTask::run() {
    mTask->run();
    mLock->lock();
    mHasRun = true;
    mSignal->signal();
    mLock->unlock();
}
+3 −1
Original line number Diff line number Diff line
@@ -60,13 +60,15 @@ class SignalingRenderTask : public RenderTask {
public:
    // Takes ownership of task, caller owns lock and signal
    SignalingRenderTask(RenderTask* task, Mutex* lock, Condition* signal)
            : mTask(task), mLock(lock), mSignal(signal) {}
            : mTask(task), mLock(lock), mSignal(signal), mHasRun(false) {}
    virtual void run() override;
    bool hasRun() const { return mHasRun; }

private:
    RenderTask* mTask;
    Mutex* mLock;
    Condition* mSignal;
    bool mHasRun;
};

typedef void* (*RunnableMethod)(void* data);
+3 −1
Original line number Diff line number Diff line
@@ -345,8 +345,10 @@ void RenderThread::queueAndWait(RenderTask* task) {

    AutoMutex _lock(mutex);
    queue(&syncTask);
    while (!syncTask.hasRun()) {
        condition.wait(mutex);
    }
}

void RenderThread::queueAtFront(RenderTask* task) {
    AutoMutex _lock(mLock);