aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core
diff options
context:
space:
mode:
authorGravatar Mike Klein <mtklein@chromium.org>2017-08-24 11:17:55 -0400
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-08-24 15:37:36 +0000
commitf3c99eecc07a0ac64dc8e796c05fa6df71ea1119 (patch)
treef6bdf529ef2147c3ed501c7ad7529c9aca377d56 /src/core
parent76323bc0615044a5921afef0e19a350f3d04ffe0 (diff)
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 <brianosman@google.com> Commit-Queue: Mike Klein <mtklein@chromium.org>
Diffstat (limited to 'src/core')
-rw-r--r--src/core/SkTaskGroup.cpp6
-rw-r--r--src/core/SkTaskGroup.h7
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<void(int)> 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<void(int)> 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.