Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(164)

Unified Diff: src/core/SkTaskGroup.cpp

Issue 1733323002: Clean up EGL thread state at thread exit in nanobench and DM (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix main thread usage also Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/core/SkTaskGroup.h ('k') | src/gpu/GrContextFactory.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkTaskGroup.cpp
diff --git a/src/core/SkTaskGroup.cpp b/src/core/SkTaskGroup.cpp
index b3c23b649beaece214b2531a13569dc790aefd46..1b542a63f51aed4e5548d335ae4d34ca614642e1 100644
--- a/src/core/SkTaskGroup.cpp
+++ b/src/core/SkTaskGroup.cpp
@@ -96,7 +96,8 @@ private:
SkAtomic<int32_t>* pending; // then decrement pending afterwards.
};
- explicit ThreadPool(int threads) {
+ explicit ThreadPool(int threads, std::function<void(void)> cleanupFn)
+ : fCleanupFn(cleanupFn) {
if (threads == -1) {
threads = sk_num_cores();
}
@@ -161,6 +162,9 @@ private:
pool->fWork.pop_back();
}
if (!work.fn) {
+ if (pool->fCleanupFn) {
+ pool->fCleanupFn();
+ }
return; // Poison pill. Time... to die.
}
work.fn();
@@ -183,6 +187,8 @@ private:
// These are only changed in a single-threaded context.
SkTDArray<SkThread*> fThreads;
+
+ std::function<void(void)> fCleanupFn;
static ThreadPool* gGlobal;
friend struct SkTaskGroup::Enabler;
@@ -191,14 +197,20 @@ ThreadPool* ThreadPool::gGlobal = nullptr;
} // namespace
-SkTaskGroup::Enabler::Enabler(int threads) {
+SkTaskGroup::Enabler::Enabler(int threads, std::function<void(void)> cleanupFn)
+ : fCleanupFn(cleanupFn) {
SkASSERT(ThreadPool::gGlobal == nullptr);
if (threads != 0) {
- ThreadPool::gGlobal = new ThreadPool(threads);
+ ThreadPool::gGlobal = new ThreadPool(threads, cleanupFn);
}
}
-SkTaskGroup::Enabler::~Enabler() { delete ThreadPool::gGlobal; }
+SkTaskGroup::Enabler::~Enabler() {
+ if (!ThreadPool::gGlobal && fCleanupFn) {
+ fCleanupFn();
+ }
+ delete ThreadPool::gGlobal;
+}
SkTaskGroup::SkTaskGroup() : fPending(0) {}
« no previous file with comments | « src/core/SkTaskGroup.h ('k') | src/gpu/GrContextFactory.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698