| OLD | NEW |
| 1 #include "SkTaskGroup.h" | 1 #include "SkTaskGroup.h" |
| 2 | 2 |
| 3 #include "SkCondVar.h" | 3 #include "SkCondVar.h" |
| 4 #include "SkTDArray.h" | 4 #include "SkTDArray.h" |
| 5 #include "SkThread.h" | 5 #include "SkThread.h" |
| 6 #include "SkThreadUtils.h" | 6 #include "SkThreadUtils.h" |
| 7 | 7 |
| 8 #if defined(SK_BUILD_FOR_WIN32) | 8 #if defined(SK_BUILD_FOR_WIN32) |
| 9 static inline int num_cores() { | 9 static inline int num_cores() { |
| 10 SYSTEM_INFO sysinfo; | 10 SYSTEM_INFO sysinfo; |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 60 private: | 60 private: |
| 61 SkCondVar* fC; | 61 SkCondVar* fC; |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 struct Work { | 64 struct Work { |
| 65 SkRunnable* task; // A task to ->run(), | 65 SkRunnable* task; // A task to ->run(), |
| 66 int32_t* pending; // then sk_atomic_dec(pending) afterwards. | 66 int32_t* pending; // then sk_atomic_dec(pending) afterwards. |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 explicit ThreadPool(int threads) : fDraining(false) { | 69 explicit ThreadPool(int threads) : fDraining(false) { |
| 70 if (threads == 0) { | 70 if (threads == -1) { |
| 71 threads = num_cores(); | 71 threads = num_cores(); |
| 72 } | 72 } |
| 73 for (int i = 0; i < threads; i++) { | 73 for (int i = 0; i < threads; i++) { |
| 74 fThreads.push(SkNEW_ARGS(SkThread, (&ThreadPool::Loop, this))); | 74 fThreads.push(SkNEW_ARGS(SkThread, (&ThreadPool::Loop, this))); |
| 75 fThreads.top()->start(); | 75 fThreads.top()->start(); |
| 76 } | 76 } |
| 77 } | 77 } |
| 78 | 78 |
| 79 ~ThreadPool() { | 79 ~ThreadPool() { |
| 80 SkASSERT(fWork.isEmpty()); // All SkTaskGroups should be destroyed by n
ow. | 80 SkASSERT(fWork.isEmpty()); // All SkTaskGroups should be destroyed by n
ow. |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 126 | 126 |
| 127 static ThreadPool* gGlobal; | 127 static ThreadPool* gGlobal; |
| 128 friend struct SkTaskGroup::Enabler; | 128 friend struct SkTaskGroup::Enabler; |
| 129 }; | 129 }; |
| 130 ThreadPool* ThreadPool::gGlobal = NULL; | 130 ThreadPool* ThreadPool::gGlobal = NULL; |
| 131 | 131 |
| 132 } // namespace | 132 } // namespace |
| 133 | 133 |
| 134 SkTaskGroup::Enabler::Enabler(int threads) { | 134 SkTaskGroup::Enabler::Enabler(int threads) { |
| 135 SkASSERT(ThreadPool::gGlobal == NULL); | 135 SkASSERT(ThreadPool::gGlobal == NULL); |
| 136 ThreadPool::gGlobal = SkNEW_ARGS(ThreadPool, (threads)); | 136 if (threads != 0) { |
| 137 ThreadPool::gGlobal = SkNEW_ARGS(ThreadPool, (threads)); |
| 138 } |
| 137 } | 139 } |
| 138 | 140 |
| 139 SkTaskGroup::Enabler::~Enabler() { | 141 SkTaskGroup::Enabler::~Enabler() { |
| 140 SkASSERT(ThreadPool::gGlobal != NULL); | |
| 141 SkDELETE(ThreadPool::gGlobal); | 142 SkDELETE(ThreadPool::gGlobal); |
| 142 } | 143 } |
| 143 | 144 |
| 144 SkTaskGroup::SkTaskGroup() : fPending(0) {} | 145 SkTaskGroup::SkTaskGroup() : fPending(0) {} |
| 145 | 146 |
| 146 void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPending); } | 147 void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPending); } |
| 147 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending); } | 148 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending); } |
| 148 | 149 |
| OLD | NEW |