SkThreadPool: tweak two little things that have been annoying me
1) it's pretty annoying that SkThreadPool doesn't include SkRunnable for us;
2) add wait() so we don't have to keep using SkAutoTDelete/free() to wait for completion.
BUG=
R=scroggo@google.com, reed@google.com
Author: mtklein@google.com
Review URL: https://codereview.chromium.org/26470005
git-svn-id: http://skia.googlecode.com/svn/trunk/src@11711 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/utils/SkThreadPool.cpp b/utils/SkThreadPool.cpp
index 3d19d1c..e078af3 100644
--- a/utils/SkThreadPool.cpp
+++ b/utils/SkThreadPool.cpp
@@ -39,6 +39,12 @@
}
SkThreadPool::~SkThreadPool() {
+ if (!fDone) {
+ this->wait();
+ }
+}
+
+void SkThreadPool::wait() {
fReady.lock();
fDone = true;
fReady.broadcast();
@@ -99,6 +105,7 @@
// We have some threads. Queue it up!
fReady.lock();
+ SkASSERT(!fDone); // We shouldn't be adding work to a pool that's shut down.
LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable);
linkedRunnable->fRunnable = r;
fQueue.addToHead(linkedRunnable);