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

Unified Diff: tools/threadpool/ThreadPool.h

Issue 371853005: Move threadpool code from include/utils to tools/threadpool. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: gyp Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/threadpool/Runnable.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/threadpool/ThreadPool.h
diff --git a/include/utils/SkThreadPool.h b/tools/threadpool/ThreadPool.h
similarity index 75%
rename from include/utils/SkThreadPool.h
rename to tools/threadpool/ThreadPool.h
index c99c5c4188a5b636f8213ce655f5138fb28f79a0..a71e36f0a7e3213a257effaafbad8c6939e6aac1 100644
--- a/include/utils/SkThreadPool.h
+++ b/tools/threadpool/ThreadPool.h
@@ -5,11 +5,11 @@
* found in the LICENSE file.
*/
-#ifndef SkThreadPool_DEFINED
-#define SkThreadPool_DEFINED
+#ifndef ThreadPool_DEFINED
+#define ThreadPool_DEFINED
-#include "SkCondVar.h"
-#include "SkRunnable.h"
+#include "CondVar.h"
+#include "Runnable.h"
#include "SkTDArray.h"
#include "SkTInternalLList.h"
#include "SkThreadUtils.h"
@@ -33,35 +33,35 @@ static inline int num_cores() {
}
template <typename T>
-class SkTThreadPool {
+class TThreadPool {
public:
/**
* Create a threadpool with count threads, or one thread per core if kThreadPerCore.
*/
static const int kThreadPerCore = -1;
- explicit SkTThreadPool(int count);
- ~SkTThreadPool();
+ explicit TThreadPool(int count);
+ ~TThreadPool();
/**
- * Queues up an SkRunnable to run when a thread is available, or synchronously if count is 0.
+ * Queues up an Runnable to run when a thread is available, or synchronously if count is 0.
* Does not take ownership. NULL is a safe no-op. If T is not void, the runnable will be passed
* a reference to a T on the thread's local stack.
*/
- void add(SkTRunnable<T>*);
+ void add(TRunnable<T>*);
/**
* Same as add, but adds the runnable as the very next to run rather than enqueueing it.
*/
- void addNext(SkTRunnable<T>*);
+ void addNext(TRunnable<T>*);
/**
- * Block until all added SkRunnables have completed. Once called, calling add() is undefined.
+ * Block until all added Runnables have completed. Once called, calling add() is undefined.
*/
void wait();
private:
struct LinkedRunnable {
- SkTRunnable<T>* fRunnable; // Unowned.
+ TRunnable<T>* fRunnable; // Unowned.
SK_DECLARE_INTERNAL_LLIST_INTERFACE(LinkedRunnable);
};
@@ -71,11 +71,11 @@ public:
kHalting_State, // There's no work to do and no thread is busy. All threads can shut down.
};
- void addSomewhere(SkTRunnable<T>* r,
+ void addSomewhere(TRunnable<T>* r,
void (SkTInternalLList<LinkedRunnable>::*)(LinkedRunnable*));
SkTInternalLList<LinkedRunnable> fQueue;
- SkCondVar fReady;
+ CondVar fReady;
SkTDArray<SkThread*> fThreads;
State fState;
int fBusyThreads;
@@ -84,49 +84,49 @@ public:
};
template <typename T>
-SkTThreadPool<T>::SkTThreadPool(int count) : fState(kRunning_State), fBusyThreads(0) {
+TThreadPool<T>::TThreadPool(int count) : fState(kRunning_State), fBusyThreads(0) {
if (count < 0) {
count = num_cores();
}
- // Create count threads, all running SkTThreadPool::Loop.
+ // Create count threads, all running TThreadPool::Loop.
for (int i = 0; i < count; i++) {
- SkThread* thread = SkNEW_ARGS(SkThread, (&SkTThreadPool::Loop, this));
+ SkThread* thread = SkNEW_ARGS(SkThread, (&TThreadPool::Loop, this));
*fThreads.append() = thread;
thread->start();
}
}
template <typename T>
-SkTThreadPool<T>::~SkTThreadPool() {
+TThreadPool<T>::~TThreadPool() {
if (kRunning_State == fState) {
this->wait();
}
}
-namespace SkThreadPoolPrivate {
+namespace ThreadPoolPrivate {
template <typename T>
struct ThreadLocal {
- void run(SkTRunnable<T>* r) { r->run(data); }
+ void run(TRunnable<T>* r) { r->run(data); }
T data;
};
template <>
struct ThreadLocal<void> {
- void run(SkTRunnable<void>* r) { r->run(); }
+ void run(TRunnable<void>* r) { r->run(); }
};
-} // namespace SkThreadPoolPrivate
+} // namespace ThreadPoolPrivate
template <typename T>
-void SkTThreadPool<T>::addSomewhere(SkTRunnable<T>* r,
+void TThreadPool<T>::addSomewhere(TRunnable<T>* r,
void (SkTInternalLList<LinkedRunnable>::* f)(LinkedRunnable*)) {
if (r == NULL) {
return;
}
if (fThreads.isEmpty()) {
- SkThreadPoolPrivate::ThreadLocal<T> threadLocal;
+ ThreadPoolPrivate::ThreadLocal<T> threadLocal;
threadLocal.run(r);
return;
}
@@ -141,18 +141,18 @@ void SkTThreadPool<T>::addSomewhere(SkTRunnable<T>* r,
}
template <typename T>
-void SkTThreadPool<T>::add(SkTRunnable<T>* r) {
+void TThreadPool<T>::add(TRunnable<T>* r) {
this->addSomewhere(r, &SkTInternalLList<LinkedRunnable>::addToTail);
}
template <typename T>
-void SkTThreadPool<T>::addNext(SkTRunnable<T>* r) {
+void TThreadPool<T>::addNext(TRunnable<T>* r) {
this->addSomewhere(r, &SkTInternalLList<LinkedRunnable>::addToHead);
}
template <typename T>
-void SkTThreadPool<T>::wait() {
+void TThreadPool<T>::wait() {
fReady.lock();
fState = kWaiting_State;
fReady.broadcast();
@@ -167,10 +167,10 @@ void SkTThreadPool<T>::wait() {
}
template <typename T>
-/*static*/ void SkTThreadPool<T>::Loop(void* arg) {
- // The SkTThreadPool passes itself as arg to each thread as they're created.
- SkTThreadPool<T>* pool = static_cast<SkTThreadPool<T>*>(arg);
- SkThreadPoolPrivate::ThreadLocal<T> threadLocal;
+/*static*/ void TThreadPool<T>::Loop(void* arg) {
+ // The TThreadPool passes itself as arg to each thread as they're created.
+ TThreadPool<T>* pool = static_cast<TThreadPool<T>*>(arg);
+ ThreadPoolPrivate::ThreadLocal<T> threadLocal;
while (true) {
// We have to be holding the lock to read the queue and to call wait.
@@ -197,7 +197,7 @@ template <typename T>
pool->fQueue.remove(r);
- // Having claimed our SkRunnable, we now give up the lock while we run it.
+ // Having claimed our Runnable, we now give up the lock while we run it.
// Otherwise, we'd only ever do work on one thread at a time, which rather
// defeats the point of this code.
pool->fBusyThreads++;
@@ -216,6 +216,6 @@ template <typename T>
SkASSERT(false); // Unreachable. The only exit happens when pool->fState is kHalting_State.
}
-typedef SkTThreadPool<void> SkThreadPool;
+typedef TThreadPool<void> ThreadPool;
#endif
« no previous file with comments | « tools/threadpool/Runnable.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698