Let SkTaskGroup work synchronously if no one created an SkTaskGroup::Enabler.
Tested by running DM with its SkTaskGroup::Enabler commented out. Slow, but completed correctly.
BUG=skia:
R=reed@google.com, mtklein@google.com
Author: mtklein@chromium.org
Review URL: https://codereview.chromium.org/556223003
diff --git a/src/utils/SkTaskGroup.cpp b/src/utils/SkTaskGroup.cpp
index e7de6be..7449eb6 100644
--- a/src/utils/SkTaskGroup.cpp
+++ b/src/utils/SkTaskGroup.cpp
@@ -23,12 +23,17 @@
class ThreadPool : SkNoncopyable {
public:
static void Add(SkRunnable* task, int32_t* pending) {
- SkASSERT(gGlobal); // If this fails, see SkTaskGroup::Enabler.
+ if (!gGlobal) { // If we have no threads, run synchronously.
+ return task->run();
+ }
gGlobal->add(task, pending);
}
static void Wait(int32_t* pending) {
- SkASSERT(gGlobal); // If this fails, see SkTaskGroup::Enabler.
+ if (!gGlobal) { // If we have no threads, the work must already be done.
+ SkASSERT(*pending == 0);
+ return;
+ }
while (sk_acquire_load(pending) > 0) { // Pairs with sk_atomic_dec here or in Loop.
// Lend a hand until our SkTaskGroup of interest is done.
Work work;