| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2014 Google Inc. | 2 * Copyright 2014 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 "SkOnce.h" | 8 #include "SkOnce.h" |
| 9 #include "SkRunnable.h" | 9 #include "SkRunnable.h" |
| 10 #include "SkSemaphore.h" | 10 #include "SkSemaphore.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 fThreads.top()->start(); | 115 fThreads.top()->start(); |
| 116 } | 116 } |
| 117 } | 117 } |
| 118 | 118 |
| 119 ~ThreadPool() { | 119 ~ThreadPool() { |
| 120 SkASSERT(fWork.isEmpty()); // All SkTaskGroups should be destroyed by n
ow. | 120 SkASSERT(fWork.isEmpty()); // All SkTaskGroups should be destroyed by n
ow. |
| 121 | 121 |
| 122 // Send a poison pill to each thread. | 122 // Send a poison pill to each thread. |
| 123 SkAtomic<int> dummy(0); | 123 SkAtomic<int> dummy(0); |
| 124 for (int i = 0; i < fThreads.count(); i++) { | 124 for (int i = 0; i < fThreads.count(); i++) { |
| 125 this->add(NULL, NULL, &dummy); | 125 this->add(nullptr, nullptr, &dummy); |
| 126 } | 126 } |
| 127 // Wait for them all to swallow the pill and die. | 127 // Wait for them all to swallow the pill and die. |
| 128 for (int i = 0; i < fThreads.count(); i++) { | 128 for (int i = 0; i < fThreads.count(); i++) { |
| 129 fThreads[i]->join(); | 129 fThreads[i]->join(); |
| 130 } | 130 } |
| 131 SkASSERT(fWork.isEmpty()); // Can't hurt to double check. | 131 SkASSERT(fWork.isEmpty()); // Can't hurt to double check. |
| 132 fThreads.deleteAll(); | 132 fThreads.deleteAll(); |
| 133 } | 133 } |
| 134 | 134 |
| 135 void add(void (*fn)(void*), void* arg, SkAtomic<int32_t>* pending) { | 135 void add(void (*fn)(void*), void* arg, SkAtomic<int32_t>* pending) { |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 190 // So fWorkAvailable may overcount actual the work available. | 190 // So fWorkAvailable may overcount actual the work available. |
| 191 // We make do, but this means some worker threads may wake spuriously. | 191 // We make do, but this means some worker threads may wake spuriously. |
| 192 SkSemaphore fWorkAvailable; | 192 SkSemaphore fWorkAvailable; |
| 193 | 193 |
| 194 // These are only changed in a single-threaded context. | 194 // These are only changed in a single-threaded context. |
| 195 SkTDArray<SkThread*> fThreads; | 195 SkTDArray<SkThread*> fThreads; |
| 196 static ThreadPool* gGlobal; | 196 static ThreadPool* gGlobal; |
| 197 | 197 |
| 198 friend struct SkTaskGroup::Enabler; | 198 friend struct SkTaskGroup::Enabler; |
| 199 }; | 199 }; |
| 200 ThreadPool* ThreadPool::gGlobal = NULL; | 200 ThreadPool* ThreadPool::gGlobal = nullptr; |
| 201 | 201 |
| 202 } // namespace | 202 } // namespace |
| 203 | 203 |
| 204 SkTaskGroup::Enabler::Enabler(int threads) { | 204 SkTaskGroup::Enabler::Enabler(int threads) { |
| 205 SkASSERT(ThreadPool::gGlobal == NULL); | 205 SkASSERT(ThreadPool::gGlobal == nullptr); |
| 206 if (threads != 0) { | 206 if (threads != 0) { |
| 207 ThreadPool::gGlobal = new ThreadPool(threads); | 207 ThreadPool::gGlobal = new ThreadPool(threads); |
| 208 } | 208 } |
| 209 } | 209 } |
| 210 | 210 |
| 211 SkTaskGroup::Enabler::~Enabler() { delete ThreadPool::gGlobal; } | 211 SkTaskGroup::Enabler::~Enabler() { delete ThreadPool::gGlobal; } |
| 212 | 212 |
| 213 SkTaskGroup::SkTaskGroup() : fPending(0) {} | 213 SkTaskGroup::SkTaskGroup() : fPending(0) {} |
| 214 | 214 |
| 215 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending
); } | 215 void SkTaskGroup::wait() { ThreadPool::Wait(&fPending
); } |
| 216 void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPe
nding); } | 216 void SkTaskGroup::add(SkRunnable* task) { ThreadPool::Add(task, &fPe
nding); } |
| 217 void SkTaskGroup::add(void (*fn)(void*), void* arg) { ThreadPool::Add(fn, arg, &
fPending); } | 217 void SkTaskGroup::add(void (*fn)(void*), void* arg) { ThreadPool::Add(fn, arg, &
fPending); } |
| 218 void SkTaskGroup::batch (void (*fn)(void*), void* args, int N, size_t stride) { | 218 void SkTaskGroup::batch (void (*fn)(void*), void* args, int N, size_t stride) { |
| 219 ThreadPool::Batch(fn, args, N, stride, &fPending); | 219 ThreadPool::Batch(fn, args, N, stride, &fPending); |
| 220 } | 220 } |
| 221 | 221 |
| OLD | NEW |