From cba287b9716155183faf21865a6c28ba49ffe486 Mon Sep 17 00:00:00 2001 From: John Reck Date: Tue, 10 Nov 2015 12:52:44 -0800 Subject: [PATCH] Fix threading issues Bug: 25584167 Change-Id: I413ef9e0c86f7cca1f7d085e0071745ca0192853 --- libs/hwui/renderthread/RenderProxy.cpp | 5 ++++- libs/hwui/renderthread/RenderProxy.h | 3 +++ libs/hwui/renderthread/RenderThread.cpp | 14 +++++++++++--- libs/hwui/renderthread/RenderThread.h | 4 ---- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/libs/hwui/renderthread/RenderProxy.cpp b/libs/hwui/renderthread/RenderProxy.cpp index a1107f029691c..15ccd6ac5b6bc 100644 --- a/libs/hwui/renderthread/RenderProxy.cpp +++ b/libs/hwui/renderthread/RenderProxy.cpp @@ -563,7 +563,10 @@ void RenderProxy::post(RenderTask* task) { void* RenderProxy::postAndWait(MethodInvokeRenderTask* task) { void* retval; task->setReturnPtr(&retval); - mRenderThread.queueAndWait(task); + SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); + AutoMutex _lock(mSyncMutex); + mRenderThread.queue(&syncTask); + mSyncCondition.wait(mSyncMutex); return retval; } diff --git a/libs/hwui/renderthread/RenderProxy.h b/libs/hwui/renderthread/RenderProxy.h index d0e601e09be68..338fab650876c 100644 --- a/libs/hwui/renderthread/RenderProxy.h +++ b/libs/hwui/renderthread/RenderProxy.h @@ -117,6 +117,9 @@ private: DrawFrameTask mDrawFrameTask; + Mutex mSyncMutex; + Condition mSyncCondition; + void destroyContext(); void post(RenderTask* task); diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 526a84861d98b..9fb30c928c005 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -25,7 +25,9 @@ #include #include #include +#include #include +#include namespace android { namespace uirenderer { @@ -325,10 +327,16 @@ void RenderThread::queue(RenderTask* task) { } void RenderThread::queueAndWait(RenderTask* task) { - SignalingRenderTask syncTask(task, &mSyncMutex, &mSyncCondition); - AutoMutex _lock(mSyncMutex); + // These need to be local to the thread to avoid the Condition + // signaling the wrong thread. The easiest way to achieve that is to just + // make this on the stack, although that has a slight cost to it + Mutex mutex; + Condition condition; + SignalingRenderTask syncTask(task, &mutex, &condition); + + AutoMutex _lock(mutex); queue(&syncTask); - mSyncCondition.wait(mSyncMutex); + condition.wait(mutex); } void RenderThread::queueAtFront(RenderTask* task) { diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index d8c7e61f34eb0..076e3d43a2c9b 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -27,9 +27,7 @@ #include #include -#include #include -#include #include namespace android { @@ -127,8 +125,6 @@ private: nsecs_t mNextWakeup; TaskQueue mQueue; - Mutex mSyncMutex; - Condition mSyncCondition; DisplayInfo mDisplayInfo;