diff options
| author | 2019-02-05 15:31:28 -0500 | |
|---|---|---|
| committer | 2019-02-05 16:26:58 -0500 | |
| commit | 80dbc35555d21f65fcfe4ede5d7b406cc4190a97 (patch) | |
| tree | 7987c3c94fce4914026bd2b9cbd42674c19b2a21 | |
| parent | 912ca4023c22c53d3526ce89fd6e7e1a90fe8e58 (diff) | |
Tell JVM to not wait for HWUI worker threads upon shutdown
RenderThread is setup as a daemon thread, which allows JVM to
exit without waiting on it. This CL does same setup for HWUI
worker threads, which offload work from the RenderThread.
This fixes an issue exposed by Vulkan pipeline, which is pushing
different loads to the worker threads and causing some java tests
to hang on exit. This is not a Vulkan specific issue, because GL
also hangs if worker thread is started.
Bug: 123374538
Test: Ran DismissDialogsInstrumentation test
Change-Id: Ie4ee94737ced975323a0792f57f8426c958e8056
| -rw-r--r-- | core/jni/android_view_ThreadedRenderer.cpp | 2 | ||||
| -rw-r--r-- | libs/hwui/renderthread/RenderThread.cpp | 8 | ||||
| -rw-r--r-- | libs/hwui/renderthread/RenderThread.h | 5 | ||||
| -rw-r--r-- | libs/hwui/thread/TaskManager.cpp | 6 | ||||
| -rw-r--r-- | libs/hwui/thread/TaskManager.h | 3 |
5 files changed, 19 insertions, 5 deletions
diff --git a/core/jni/android_view_ThreadedRenderer.cpp b/core/jni/android_view_ThreadedRenderer.cpp index 40529191a42c..2c058cd0d6fd 100644 --- a/core/jni/android_view_ThreadedRenderer.cpp +++ b/core/jni/android_view_ThreadedRenderer.cpp @@ -1207,7 +1207,7 @@ static void attachRenderThreadToJvm() { JavaVMAttachArgs args; args.version = JNI_VERSION_1_4; - args.name = (char*) "RenderThread"; + args.name = NULL; args.group = NULL; JNIEnv* env; mJvm->AttachCurrentThreadAsDaemon(&env, (void*) &args); diff --git a/libs/hwui/renderthread/RenderThread.cpp b/libs/hwui/renderthread/RenderThread.cpp index 8bef35915c4d..caad80651395 100644 --- a/libs/hwui/renderthread/RenderThread.cpp +++ b/libs/hwui/renderthread/RenderThread.cpp @@ -56,7 +56,7 @@ static const nsecs_t DISPATCH_FRAME_CALLBACKS_DELAY = milliseconds_to_nanosecond static bool gHasRenderThreadInstance = false; -static void (*gOnStartHook)() = nullptr; +static JVMAttachHook gOnStartHook = nullptr; class DisplayEventReceiverWrapper : public VsyncSource { public: @@ -111,11 +111,15 @@ bool RenderThread::hasInstance() { return gHasRenderThreadInstance; } -void RenderThread::setOnStartHook(void (*onStartHook)()) { +void RenderThread::setOnStartHook(JVMAttachHook onStartHook) { LOG_ALWAYS_FATAL_IF(hasInstance(), "can't set an onStartHook after we've started..."); gOnStartHook = onStartHook; } +JVMAttachHook RenderThread::getOnStartHook() { + return gOnStartHook; +} + RenderThread& RenderThread::getInstance() { // This is a pointer because otherwise __cxa_finalize // will try to delete it like a Good Citizen but that causes us to crash diff --git a/libs/hwui/renderthread/RenderThread.h b/libs/hwui/renderthread/RenderThread.h index 1ef83fb26c14..d062dba288fc 100644 --- a/libs/hwui/renderthread/RenderThread.h +++ b/libs/hwui/renderthread/RenderThread.h @@ -75,12 +75,15 @@ struct VsyncSource { class DummyVsyncSource; +typedef void (*JVMAttachHook)(); + class RenderThread : private ThreadBase { PREVENT_COPY_AND_ASSIGN(RenderThread); public: // Sets a callback that fires before any RenderThread setup has occurred. - ANDROID_API static void setOnStartHook(void (*onStartHook)()); + ANDROID_API static void setOnStartHook(JVMAttachHook onStartHook); + static JVMAttachHook getOnStartHook(); WorkQueue& queue() { return ThreadBase::queue(); } diff --git a/libs/hwui/thread/TaskManager.cpp b/libs/hwui/thread/TaskManager.cpp index 26ff6ebad3b4..6493d495716e 100644 --- a/libs/hwui/thread/TaskManager.cpp +++ b/libs/hwui/thread/TaskManager.cpp @@ -21,6 +21,7 @@ #include "TaskManager.h" #include "TaskProcessor.h" #include "utils/MathUtils.h" +#include "renderthread/RenderThread.h" namespace android { namespace uirenderer { @@ -84,6 +85,11 @@ bool TaskManager::addTaskBase(const sp<TaskBase>& task, const sp<TaskProcessorBa status_t TaskManager::WorkerThread::readyToRun() { setpriority(PRIO_PROCESS, 0, PRIORITY_FOREGROUND); + auto onStartHook = renderthread::RenderThread::getOnStartHook(); + if (onStartHook) { + onStartHook(); + } + return NO_ERROR; } diff --git a/libs/hwui/thread/TaskManager.h b/libs/hwui/thread/TaskManager.h index c4c1291e755c..6c67222a12d7 100644 --- a/libs/hwui/thread/TaskManager.h +++ b/libs/hwui/thread/TaskManager.h @@ -77,7 +77,8 @@ private: class WorkerThread : public Thread { public: - explicit WorkerThread(const String8& name) : mSignal(Condition::WAKE_UP_ONE), mName(name) {} + explicit WorkerThread(const String8& name) + : Thread(false), mSignal(Condition::WAKE_UP_ONE), mName(name) {} bool addTask(const TaskWrapper& task); size_t getTaskCount() const; |