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>
This commit is contained in:
Mike Klein 2017-08-24 11:17:55 -04:00 committed by Skia Commit-Bot
parent 76323bc061
commit f3c99eecc0
2 changed files with 10 additions and 3 deletions

View File

@ -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();
}
}

View File

@ -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.