Chromium Code Reviews| 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 #include "SkRunnable.h" | |
| 8 #include "SkThreadPool.h" | 9 #include "SkThreadPool.h" |
| 9 #include "SkRunnable.h" | |
| 10 #include "SkThreadUtils.h" | 10 #include "SkThreadUtils.h" |
| 11 #include "SkTypes.h" | |
| 11 | 12 |
| 12 SkThreadPool::SkThreadPool(const int count) | 13 #if defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) |
| 14 #include <unistd.h> | |
| 15 #endif | |
| 16 | |
| 17 namespace { | |
| 18 // Returns the number of cores on this machine. | |
| 19 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.
| |
| 20 #if defined(SK_BUILD_FOR_WIN32) | |
| 21 SYSTEM_INFO sysinfo; | |
| 22 GetSystemInfo(&sysinfo); | |
| 23 return sysinfo.dwNumberOfProcessors; | |
| 24 #elif defined(SK_BUILD_FOR_UNIX) || defined(SK_BUILD_FOR_MAC) | |
| 25 return sysconf(_SC_NPROCESSORS_ONLN); | |
| 26 #else | |
| 27 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.
| |
| 28 #endif | |
| 29 } | |
| 30 } // namespace | |
| 31 | |
| 32 SkThreadPool::SkThreadPool(int count) | |
| 13 : fDone(false) { | 33 : fDone(false) { |
| 34 if (count < 0) count = numCores(); | |
| 14 // Create count threads, all running SkThreadPool::Loop. | 35 // Create count threads, all running SkThreadPool::Loop. |
| 15 for (int i = 0; i < count; i++) { | 36 for (int i = 0; i < count; i++) { |
| 16 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); | 37 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); |
| 17 *fThreads.append() = thread; | 38 *fThreads.append() = thread; |
| 18 thread->start(); | 39 thread->start(); |
| 19 } | 40 } |
| 20 } | 41 } |
| 21 | 42 |
| 22 SkThreadPool::~SkThreadPool() { | 43 SkThreadPool::~SkThreadPool() { |
| 23 fDone = true; | 44 fDone = true; |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 } | 100 } |
| 80 | 101 |
| 81 // We have some threads. Queue it up! | 102 // We have some threads. Queue it up! |
| 82 fReady.lock(); | 103 fReady.lock(); |
| 83 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable); | 104 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable); |
| 84 linkedRunnable->fRunnable = r; | 105 linkedRunnable->fRunnable = r; |
| 85 fQueue.addToHead(linkedRunnable); | 106 fQueue.addToHead(linkedRunnable); |
| 86 fReady.signal(); | 107 fReady.signal(); |
| 87 fReady.unlock(); | 108 fReady.unlock(); |
| 88 } | 109 } |
| OLD | NEW |