Index: include/utils/SkThreadPool.h |
diff --git a/include/utils/SkThreadPool.h b/include/utils/SkThreadPool.h |
index a75bed8be44f538eeb87d3c21658f2de83290618..295b1b4f080004edb111f51570a5beb74b0371b8 100644 |
--- a/include/utils/SkThreadPool.h |
+++ b/include/utils/SkThreadPool.h |
@@ -50,6 +50,11 @@ public: |
void add(SkTRunnable<T>*); |
/** |
+ * Same as add, but adds the runnable as the very next to run rather than enqueueing it. |
+ */ |
+ void addNext(SkTRunnable<T>*); |
+ |
+ /** |
* Block until all added SkRunnables have completed. Once called, calling add() is undefined. |
*/ |
void wait(); |
@@ -66,6 +71,9 @@ 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 (SkTInternalLList<LinkedRunnable>::*)(LinkedRunnable*)); |
+ |
SkTInternalLList<LinkedRunnable> fQueue; |
SkCondVar fReady; |
SkTDArray<SkThread*> fThreads; |
@@ -111,7 +119,8 @@ struct ThreadLocal<void> { |
} // namespace SkThreadPoolPrivate |
template <typename T> |
-void SkTThreadPool<T>::add(SkTRunnable<T>* r) { |
+void SkTThreadPool<T>::addSomewhere(SkTRunnable<T>* r, |
+ void (SkTInternalLList<LinkedRunnable>::* f)(LinkedRunnable*)) { |
if (r == NULL) { |
return; |
} |
@@ -126,11 +135,21 @@ void SkTThreadPool<T>::add(SkTRunnable<T>* r) { |
linkedRunnable->fRunnable = r; |
fReady.lock(); |
SkASSERT(fState != kHalting_State); // Shouldn't be able to add work when we're halting. |
- fQueue.addToHead(linkedRunnable); |
+ (fQueue.*f)(linkedRunnable); |
fReady.signal(); |
fReady.unlock(); |
} |
+template <typename T> |
+void SkTThreadPool<T>::add(SkTRunnable<T>* r) { |
+ this->addSomewhere(r, &SkTInternalLList<LinkedRunnable>::addToTail); |
+} |
+ |
+template <typename T> |
+void SkTThreadPool<T>::addNext(SkTRunnable<T>* r) { |
+ this->addSomewhere(r, &SkTInternalLList<LinkedRunnable>::addToHead); |
+} |
+ |
template <typename T> |
void SkTThreadPool<T>::wait() { |
@@ -174,7 +193,7 @@ template <typename T> |
// We've got the lock back here, no matter if we ran wait or not. |
// The queue is not empty, so we have something to run. Claim it. |
- LinkedRunnable* r = pool->fQueue.tail(); |
+ LinkedRunnable* r = pool->fQueue.head(); |
pool->fQueue.remove(r); |