From f3c99eecc07a0ac64dc8e796c05fa6df71ea1119 Mon Sep 17 00:00:00 2001 From: Mike Klein Date: Thu, 24 Aug 2017 11:17:55 -0400 Subject: [PATCH] add SkTaskGroup::done() This lets you check if the work's done without blocking. Seems handy. Change-Id: Ie27c7b6fe0d01262b6a777abbc18b0de108641c0 Reviewed-on: https://skia-review.googlesource.com/38120 Reviewed-by: Brian Osman Commit-Queue: Mike Klein --- src/core/SkTaskGroup.cpp | 6 +++++- src/core/SkTaskGroup.h | 7 +++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/core/SkTaskGroup.cpp b/src/core/SkTaskGroup.cpp index 9469b8c1ce..c7927db5ba 100644 --- a/src/core/SkTaskGroup.cpp +++ b/src/core/SkTaskGroup.cpp @@ -29,12 +29,16 @@ void SkTaskGroup::batch(int N, std::function fn) { } } +bool SkTaskGroup::done() const { + return fPending.load(std::memory_order_acquire) == 0; +} + void SkTaskGroup::wait() { // Actively help the executor do work until our task group is done. // This lets SkTaskGroups nest arbitrarily deep on a single SkExecutor: // no thread ever blocks waiting for others to do its work. // (We may end up doing work that's not part of our task group. That's fine.) - while (fPending.load(std::memory_order_acquire) > 0) { + while (!this->done()) { fExecutor.borrow(); } } diff --git a/src/core/SkTaskGroup.h b/src/core/SkTaskGroup.h index ff291ea29e..d33f1458cb 100644 --- a/src/core/SkTaskGroup.h +++ b/src/core/SkTaskGroup.h @@ -25,8 +25,11 @@ public: // Add a batch of N tasks, all calling fn with different arguments. void batch(int N, std::function fn); - // Block until all Tasks previously add()ed to this SkTaskGroup have run. - // You may safely reuse this SkTaskGroup after wait() returns. + // Returns true if all Tasks previously add()ed to this SkTaskGroup have run. + // It is safe to reuse this SkTaskGroup once done(). + bool done() const; + + // Block until done(). void wait(); // A convenience for testing tools.