Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(441)

Unified Diff: src/utils/SkThreadPool.cpp

Issue 13855009: Add thread-per-core setting to SkThreadPool. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: missing FOR_ Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | tests/PathOpsExtendedTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkThreadPool.cpp
diff --git a/src/utils/SkThreadPool.cpp b/src/utils/SkThreadPool.cpp
index 78cb417d071b45fd08a1c9c06815c58764176d9f..5fe10255b5ae599945cd4fa3c5051a35dcdb05f3 100644
--- a/src/utils/SkThreadPool.cpp
+++ b/src/utils/SkThreadPool.cpp
@@ -5,12 +5,31 @@
* 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) || defined(SK_BUILD_FOR_ANDROID)
+#include <unistd.h>
+#endif
+
+// Returns the number of cores on this machine.
+static int num_cores() {
+#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) || defined(SK_BUILD_FOR_ANDROID)
+ return sysconf(_SC_NPROCESSORS_ONLN);
+#else
+ return 1;
+#endif
+}
-SkThreadPool::SkThreadPool(const int count)
+SkThreadPool::SkThreadPool(int count)
: fDone(false) {
+ if (count < 0) count = num_cores();
// Create count threads, all running SkThreadPool::Loop.
for (int i = 0; i < count; i++) {
SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this));
« no previous file with comments | « include/utils/SkThreadPool.h ('k') | tests/PathOpsExtendedTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698