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 "SkRunnable.h" |
9 #include "SkThreadPool.h" | 9 #include "SkThreadPool.h" |
10 #include "SkThreadUtils.h" | 10 #include "SkThreadUtils.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 if (count < 0) count = num_cores(); | 32 if (count < 0) count = num_cores(); |
33 // Create count threads, all running SkThreadPool::Loop. | 33 // Create count threads, all running SkThreadPool::Loop. |
34 for (int i = 0; i < count; i++) { | 34 for (int i = 0; i < count; i++) { |
35 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); | 35 SkThread* thread = SkNEW_ARGS(SkThread, (&SkThreadPool::Loop, this)); |
36 *fThreads.append() = thread; | 36 *fThreads.append() = thread; |
37 thread->start(); | 37 thread->start(); |
38 } | 38 } |
39 } | 39 } |
40 | 40 |
41 SkThreadPool::~SkThreadPool() { | 41 SkThreadPool::~SkThreadPool() { |
| 42 fReady.lock(); |
42 fDone = true; | 43 fDone = true; |
43 fReady.lock(); | |
44 fReady.broadcast(); | 44 fReady.broadcast(); |
45 fReady.unlock(); | 45 fReady.unlock(); |
46 | 46 |
47 // Wait for all threads to stop. | 47 // Wait for all threads to stop. |
48 for (int i = 0; i < fThreads.count(); i++) { | 48 for (int i = 0; i < fThreads.count(); i++) { |
49 fThreads[i]->join(); | 49 fThreads[i]->join(); |
50 SkDELETE(fThreads[i]); | 50 SkDELETE(fThreads[i]); |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 98 } |
99 | 99 |
100 // We have some threads. Queue it up! | 100 // We have some threads. Queue it up! |
101 fReady.lock(); | 101 fReady.lock(); |
102 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable); | 102 LinkedRunnable* linkedRunnable = SkNEW(LinkedRunnable); |
103 linkedRunnable->fRunnable = r; | 103 linkedRunnable->fRunnable = r; |
104 fQueue.addToHead(linkedRunnable); | 104 fQueue.addToHead(linkedRunnable); |
105 fReady.signal(); | 105 fReady.signal(); |
106 fReady.unlock(); | 106 fReady.unlock(); |
107 } | 107 } |
OLD | NEW |