| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #ifndef SkThreadPool_DEFINED | 8 #ifndef SkThreadPool_DEFINED |
| 9 #define SkThreadPool_DEFINED | 9 #define SkThreadPool_DEFINED |
| 10 | 10 |
| 11 #include "SkCondVar.h" | 11 #include "SkCondVar.h" |
| 12 #include "SkTDArray.h" | 12 #include "SkTDArray.h" |
| 13 #include "SkTInternalLList.h" | 13 #include "SkTInternalLList.h" |
| 14 | 14 |
| 15 class SkRunnable; | 15 class SkRunnable; |
| 16 class SkThread; | 16 class SkThread; |
| 17 | 17 |
| 18 class SkThreadPool { | 18 class SkThreadPool { |
| 19 | 19 |
| 20 public: | 20 public: |
| 21 /** | 21 /** |
| 22 * Create a threadpool with exactly count (>=0) threads. | 22 * Create a threadpool with count threads, or one thread per core if kThread
PerCore. |
| 23 */ | 23 */ |
| 24 static const int kThreadPerCore = -1; |
| 24 explicit SkThreadPool(int count); | 25 explicit SkThreadPool(int count); |
| 25 ~SkThreadPool(); | 26 ~SkThreadPool(); |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * Queues up an SkRunnable to run when a thread is available, or immediately
if | 29 * Queues up an SkRunnable to run when a thread is available, or immediately
if |
| 29 * count is 0. NULL is a safe no-op. Does not take ownership. | 30 * count is 0. NULL is a safe no-op. Does not take ownership. |
| 30 */ | 31 */ |
| 31 void add(SkRunnable*); | 32 void add(SkRunnable*); |
| 32 | 33 |
| 33 private: | 34 private: |
| 34 struct LinkedRunnable { | 35 struct LinkedRunnable { |
| 35 // Unowned pointer. | 36 // Unowned pointer. |
| 36 SkRunnable* fRunnable; | 37 SkRunnable* fRunnable; |
| 37 | 38 |
| 38 private: | 39 private: |
| 39 SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable); | 40 SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable); |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 SkTInternalLList<LinkedRunnable> fQueue; | 43 SkTInternalLList<LinkedRunnable> fQueue; |
| 43 SkCondVar fReady; | 44 SkCondVar fReady; |
| 44 SkTDArray<SkThread*> fThreads; | 45 SkTDArray<SkThread*> fThreads; |
| 45 bool fDone; | 46 bool fDone; |
| 46 | 47 |
| 47 static void Loop(void*); // Static because we pass in this. | 48 static void Loop(void*); // Static because we pass in this. |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 #endif | 51 #endif |
| OLD | NEW |