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:
parent
76323bc061
commit
f3c99eecc0
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
Loading…
Reference in New Issue
Block a user