Add SkThreadPool for managing threads.
Skia-ized from https://codereview.appspot.com/6755043/
TODO: Use SkThread and platform independent features.
Review URL: https://codereview.appspot.com/6777064
git-svn-id: http://skia.googlecode.com/svn/trunk@6217 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/utils/SkCountdown.cpp b/src/utils/SkCountdown.cpp
new file mode 100644
index 0000000..5b476cc
--- /dev/null
+++ b/src/utils/SkCountdown.cpp
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "SkCountdown.h"
+#include "SkThread.h"
+
+SkCountdown::SkCountdown(int32_t count)
+: fCount(count) {}
+
+void SkCountdown::reset(int32_t count) {
+ fCount = count;
+}
+
+void SkCountdown::run() {
+ if (sk_atomic_dec(&fCount) == 1) {
+ fReady.lock();
+ fReady.signal();
+ fReady.unlock();
+ }
+}
+
+void SkCountdown::wait() {
+ fReady.lock();
+ while (fCount > 0) {
+ fReady.wait();
+ }
+ fReady.unlock();
+}
+