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