diff options
author | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-11 23:06:44 +0000 |
---|---|---|
committer | android-build-team Robot <android-build-team-robot@google.com> | 2021-04-11 23:06:44 +0000 |
commit | bd33c1d7942f5aad3e313cbd447056b720d1149b (patch) | |
tree | c15000b5ed150231e7633f422a89a613d6584961 /libs/hwui/thread/CommonPool.cpp | |
parent | 2946f76a85ed162fe5f401f5b2b47a79e8e79e5c (diff) | |
parent | 66915840539c1e0f82f440ef74cdf78cfeba00ec (diff) |
Snap for 7274915 from 66915840539c1e0f82f440ef74cdf78cfeba00ec to sc-release
Change-Id: I20cdf6357254e01f42dc75a1cfb4fe74ad144cb4
Diffstat (limited to 'libs/hwui/thread/CommonPool.cpp')
-rw-r--r-- | libs/hwui/thread/CommonPool.cpp | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/libs/hwui/thread/CommonPool.cpp b/libs/hwui/thread/CommonPool.cpp index d011bdfe945e..dc92f9f0d39a 100644 --- a/libs/hwui/thread/CommonPool.cpp +++ b/libs/hwui/thread/CommonPool.cpp @@ -29,14 +29,23 @@ CommonPool::CommonPool() { ATRACE_CALL(); CommonPool* pool = this; + std::mutex mLock; + std::vector<int> tids(THREAD_COUNT); + std::vector<std::condition_variable> tidConditionVars(THREAD_COUNT); + // Create 2 workers for (int i = 0; i < THREAD_COUNT; i++) { - std::thread worker([pool, i] { + std::thread worker([pool, i, &mLock, &tids, &tidConditionVars] { { std::array<char, 20> name{"hwuiTask"}; snprintf(name.data(), name.size(), "hwuiTask%d", i); auto self = pthread_self(); pthread_setname_np(self, name.data()); + { + std::unique_lock lock(mLock); + tids[i] = pthread_gettid_np(self); + tidConditionVars[i].notify_one(); + } setpriority(PRIO_PROCESS, 0, PRIORITY_FOREGROUND); auto startHook = renderthread::RenderThread::getOnStartHook(); if (startHook) { @@ -47,6 +56,15 @@ CommonPool::CommonPool() { }); worker.detach(); } + { + std::unique_lock lock(mLock); + for (int i = 0; i < THREAD_COUNT; i++) { + while (!tids[i]) { + tidConditionVars[i].wait(lock); + } + } + } + mWorkerThreadIds = std::move(tids); } CommonPool& CommonPool::instance() { @@ -58,6 +76,10 @@ void CommonPool::post(Task&& task) { instance().enqueue(std::move(task)); } +std::vector<int> CommonPool::getThreadIds() { + return instance().mWorkerThreadIds; +} + void CommonPool::enqueue(Task&& task) { std::unique_lock lock(mLock); while (!mWorkQueue.hasSpace()) { @@ -104,4 +126,4 @@ void CommonPool::doWaitForIdle() { } } // namespace uirenderer -} // namespace android
\ No newline at end of file +} // namespace android |