| 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 "SkRunnable.h" | 12 #include "SkRunnable.h" |
| 13 #include "SkTDArray.h" | 13 #include "SkTDArray.h" |
| 14 #include "SkTInternalLList.h" | 14 #include "SkTInternalLList.h" |
| 15 #include "SkThreadUtils.h" | 15 #include "SkThreadUtils.h" |
| 16 #include "SkTypes.h" | 16 #include "SkTypes.h" |
| 17 | 17 |
| 18 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_
FOR_ANDROID) | 18 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUILD_
FOR_ANDROID) |
| 19 # include <unistd.h> | 19 # include <unistd.h> |
| 20 #endif | 20 #endif |
| 21 | 21 |
| 22 // Returns the number of cores on this machine. | 22 // Returns the number of cores on this machine. |
| 23 static inline int num_cores() { | 23 static inline int num_cores() { |
| 24 #if defined(SK_BUILD_FOR_WIN32) | 24 #if defined(SK_BUILD_FOR_WIN32) |
| 25 SYSTEM_INFO sysinfo; | 25 SYSTEM_INFO sysinfo; |
| 26 GetSystemInfo(&sysinfo); | 26 GetSystemInfo(&sysinfo); |
| 27 return sysinfo.dwNumberOfProcessors; | 27 return sysinfo.dwNumberOfProcessors; |
| 28 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUIL
D_FOR_ANDROID) | 28 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) || defined(SK_BUIL
D_FOR_ANDROID) |
| 29 return sysconf(_SC_NPROCESSORS_ONLN); | 29 return (int) sysconf(_SC_NPROCESSORS_ONLN); |
| 30 #else | 30 #else |
| 31 return 1; | 31 return 1; |
| 32 #endif | 32 #endif |
| 33 } | 33 } |
| 34 | 34 |
| 35 template <typename T> | 35 template <typename T> |
| 36 class SkTThreadPool { | 36 class SkTThreadPool { |
| 37 public: | 37 public: |
| 38 /** | 38 /** |
| 39 * Create a threadpool with count threads, or one thread per core if kThread
PerCore. | 39 * Create a threadpool with count threads, or one thread per core if kThread
PerCore. |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 193 pool->fBusyThreads--; | 193 pool->fBusyThreads--; |
| 194 pool->fReady.unlock(); | 194 pool->fReady.unlock(); |
| 195 } | 195 } |
| 196 | 196 |
| 197 SkASSERT(false); // Unreachable. The only exit happens when pool->fState is
kHalting_State. | 197 SkASSERT(false); // Unreachable. The only exit happens when pool->fState is
kHalting_State. |
| 198 } | 198 } |
| 199 | 199 |
| 200 typedef SkTThreadPool<void> SkThreadPool; | 200 typedef SkTThreadPool<void> SkThreadPool; |
| 201 | 201 |
| 202 #endif | 202 #endif |
| OLD | NEW |