Merge "Tell JVM to not wait for HWUI worker threads upon shutdown"

This commit is contained in:
TreeHugger Robot
2019-02-05 23:41:59 +00:00
committed by Android (Google) Code Review
5 changed files with 19 additions and 5 deletions

View File

@@ -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);

View File

@@ -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

View File

@@ -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(); }

View File

@@ -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;
}

View File

@@ -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;