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/include/utils/SkThreadPool.h b/include/utils/SkThreadPool.h
new file mode 100644
index 0000000..a96f87b
--- /dev/null
+++ b/include/utils/SkThreadPool.h
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2012 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef SkThreadPool_DEFINED
+#define SkThreadPool_DEFINED
+
+#include "SkCondVar.h"
+#include "SkTDArray.h"
+#include "SkTDLinkedList.h"
+
+class SkRunnable;
+class SkThread;
+
+class SkThreadPool {
+
+public:
+    /**
+     * Create a threadpool with exactly count (>=0) threads.
+     */
+    explicit SkThreadPool(int count);
+    ~SkThreadPool();
+
+    /**
+     * Queues up an SkRunnable to run when a thread is available, or immediately if
+     * count is 0.  NULL is a safe no-op.  Does not take ownership.
+     */
+    void add(SkRunnable*);
+
+ private:
+    struct LinkedRunnable {
+        // Unowned pointer.
+        SkRunnable* fRunnable;
+
+    private:
+        SK_DEFINE_DLINKEDLIST_INTERFACE(LinkedRunnable)
+    };
+
+    SkTDLinkedList<LinkedRunnable> fQueue;
+    SkCondVar                      fReady;
+    SkTDArray<SkThread*>           fThreads;
+    bool                           fDone;
+
+    static void Loop(void*);  // Static because we pass in this.
+};
+
+#endif