[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
diff --git a/libs/renderengine/gl/ImageManager.cpp b/libs/renderengine/gl/ImageManager.cpp
index 5af0e4f..6256649 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 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 @@
entry.barrier->condition.notify_one();
}
}
+
+ ALOGD("Reached end of threadMain, terminating ImageManager thread!");
}
} // namespace gl