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
This commit is contained in:
@@ -685,7 +685,9 @@ void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) {
|
||||
SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition);
|
||||
AutoMutex _lock(mSyncMutex);
|
||||
mRenderThread.queue(&syncTask);
|
||||
mSyncCondition.wait(mSyncMutex);
|
||||
while (!syncTask.hasRun()) {
|
||||
mSyncCondition.wait(mSyncMutex);
|
||||
}
|
||||
return retval;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace renderthread {
|
||||
void SignalingRenderTask::run() {
|
||||
mTask->run();
|
||||
mLock->lock();
|
||||
mHasRun = true;
|
||||
mSignal->signal();
|
||||
mLock->unlock();
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -345,7 +345,9 @@ void RenderThread::queueAndWait(RenderTask* task) {
|
||||
|
||||
AutoMutex _lock(mutex);
|
||||
queue(&syncTask);
|
||||
condition.wait(mutex);
|
||||
while (!syncTask.hasRun()) {
|
||||
condition.wait(mutex);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderThread::queueAtFront(RenderTask* task) {
|
||||
|
||||
Reference in New Issue
Block a user