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

Side by Side Diff: src/utils/SkTaskGroup.cpp

Issue 636593002: Restore a really single-threaded mode to DM. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years, 2 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 unified diff | Download patch
« no previous file with comments | « src/utils/SkTaskGroup.h ('k') | tools/flags/SkCommonFlags.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
OLDNEW
« no previous file with comments | « src/utils/SkTaskGroup.h ('k') | tools/flags/SkCommonFlags.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698