diff options
| author | 2020-02-27 12:06:10 -0800 | |
|---|---|---|
| committer | 2020-02-27 12:24:41 -0800 | |
| commit | 349fd2d2761b541d83cda739c866a1af315b036f (patch) | |
| tree | 6729dd20b3551ee05c8b324578f2dab54b7e1642 | |
| parent | 1c7bc86a9b1bdf16b240a96d083102127f036325 (diff) | |
[RenderEngine] Reorder when ImageManager thread starts
Previously the background thread for managing EglImages was intialized
as a member variable before the constructor completed running. In very
rare circumstances this can potentially stop the running thread if the
thread ran before mRunning was initialized. To be less error-prone,
require that ImageManger::initThread be explicitly called to guarantee
that class member variables are well-defined when the thread begins
executing.
In case the issue resurfaces after this change, added a debug log to add
context.
Bug: 146416748
Test: builds. There is no reliable repro, so this fix is speculative
Test: systrace to verify thread is running and configured correctly.
Change-Id: I141c86240b90c7f87c22b3768c2e188293987b76
| -rw-r--r-- | libs/renderengine/gl/GLESRenderEngine.cpp | 1 | ||||
| -rw-r--r-- | libs/renderengine/gl/ImageManager.cpp | 10 | ||||
| -rw-r--r-- | libs/renderengine/gl/ImageManager.h | 6 |
3 files changed, 15 insertions, 2 deletions
diff --git a/libs/renderengine/gl/GLESRenderEngine.cpp b/libs/renderengine/gl/GLESRenderEngine.cpp index e11b59ff24..186aa25014 100644 --- a/libs/renderengine/gl/GLESRenderEngine.cpp +++ b/libs/renderengine/gl/GLESRenderEngine.cpp @@ -441,6 +441,7 @@ GLESRenderEngine::GLESRenderEngine(const RenderEngineCreationArgs& args, EGLDisp } mImageManager = std::make_unique<ImageManager>(this); + mImageManager->initThread(); mDrawingBuffer = createFramebuffer(); } diff --git a/libs/renderengine/gl/ImageManager.cpp b/libs/renderengine/gl/ImageManager.cpp index 5af0e4f857..62566494f0 100644 --- a/libs/renderengine/gl/ImageManager.cpp +++ b/libs/renderengine/gl/ImageManager.cpp @@ -14,6 +14,9 @@ * limitations under the License. */ +//#define LOG_NDEBUG 0 +#undef LOG_TAG +#define LOG_TAG "RenderEngine" #define ATRACE_TAG ATRACE_TAG_GRAPHICS #include <pthread.h> @@ -27,7 +30,10 @@ namespace android { namespace renderengine { namespace gl { -ImageManager::ImageManager(GLESRenderEngine* engine) : mEngine(engine) { +ImageManager::ImageManager(GLESRenderEngine* engine) : mEngine(engine) {} + +void ImageManager::initThread() { + mThread = std::thread([this]() { threadMain(); }); pthread_setname_np(mThread.native_handle(), "ImageManager"); // Use SCHED_FIFO to minimize jitter struct sched_param param = {0}; @@ -133,6 +139,8 @@ void ImageManager::threadMain() { entry.barrier->condition.notify_one(); } } + + ALOGD("Reached end of threadMain, terminating ImageManager thread!"); } } // namespace gl diff --git a/libs/renderengine/gl/ImageManager.h b/libs/renderengine/gl/ImageManager.h index b5ba554c4f..be67de8367 100644 --- a/libs/renderengine/gl/ImageManager.h +++ b/libs/renderengine/gl/ImageManager.h @@ -39,6 +39,10 @@ public: }; ImageManager(GLESRenderEngine* engine); ~ImageManager(); + // Starts the background thread for the ImageManager + // We need this to guarantee that the class is fully-constructed before the + // thread begins running. + void initThread(); void cacheAsync(const sp<GraphicBuffer>& buffer, const std::shared_ptr<Barrier>& barrier) EXCLUDES(mMutex); status_t cache(const sp<GraphicBuffer>& buffer); @@ -57,7 +61,7 @@ private: void queueOperation(const QueueEntry&& entry); void threadMain(); GLESRenderEngine* const mEngine; - std::thread mThread = std::thread([this]() { threadMain(); }); + std::thread mThread; std::condition_variable_any mCondition; std::mutex mMutex; std::queue<QueueEntry> mQueue GUARDED_BY(mMutex); |