Chromium Code Reviews| Index: src/utils/SkThreadPool.cpp |
| diff --git a/src/utils/SkThreadPool.cpp b/src/utils/SkThreadPool.cpp |
| index 78cb417d071b45fd08a1c9c06815c58764176d9f..ab5dd139559e00cc5e17cb91241d257463fdd92a 100644 |
| --- a/src/utils/SkThreadPool.cpp |
| +++ b/src/utils/SkThreadPool.cpp |
| @@ -5,12 +5,33 @@ |
| * found in the LICENSE file. |
| */ |
| -#include "SkThreadPool.h" |
| #include "SkRunnable.h" |
| +#include "SkThreadPool.h" |
| #include "SkThreadUtils.h" |
| +#include "SkTypes.h" |
| + |
| +#if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) |
| +#include <unistd.h> |
| +#endif |
| + |
| +namespace { |
| +// Returns the number of cores on this machine. |
| +int numCores() { |
|
scroggo
2013/04/19 18:43:35
Should this be num_cores(), as if this were a stat
mtklein
2013/04/19 18:52:59
Yes, done.
|
| +#if defined(SK_BUILD_FOR_WIN32) |
| + SYSTEM_INFO sysinfo; |
| + GetSystemInfo(&sysinfo); |
| + return sysinfo.dwNumberOfProcessors; |
| +#elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) |
| + return sysconf(_SC_NPROCESSORS_ONLN); |
| +#else |
| + return 1; |
|
caryclark
2013/04/19 18:37:12
SK_BUILD_ANDROID ?
could this use the sysconf call
mtklein
2013/04/19 18:52:59
Yes, that'll work there too. Done.
|
| +#endif |
| +} |
| +} // namespace |
| -SkThreadPool::SkThreadPool(const int count) |
| +SkThreadPool::SkThreadPool(int count) |
| : fDone(false) { |
| + if (count < 0) count = numCores(); |
| // Create count threads, all running SkThreadPool::Loop. |
| for (int i = 0; i < count; i++) { |
| SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); |