Switch SkTaskGroup to std::atomic.

No interesting change, just getting on std APIs.

Change-Id: I0f42cbb6854b49a6ae8266e5b92f977d27f4e032
Reviewed-on: https://skia-review.googlesource.com/8860
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Mike Klein <mtklein@chromium.org>
This commit is contained in:
Mike Klein 2017-02-22 13:00:33 -05:00
parent d7e86a5252
commit 416bbd97ce
2 changed files with 8 additions and 8 deletions

View File

@ -11,20 +11,20 @@
SkTaskGroup::SkTaskGroup(SkExecutor& executor) : fPending(0), fExecutor(executor) {}
void SkTaskGroup::add(std::function<void(void)> fn) {
fPending.fetch_add(+1, sk_memory_order_relaxed);
fPending.fetch_add(+1, std::memory_order_relaxed);
fExecutor.add([=] {
fn();
fPending.fetch_add(-1, sk_memory_order_release);
fPending.fetch_add(-1, std::memory_order_release);
});
}
void SkTaskGroup::batch(int N, std::function<void(int)> fn) {
// TODO: I really thought we had some sort of more clever chunking logic.
fPending.fetch_add(+N, sk_memory_order_relaxed);
fPending.fetch_add(+N, std::memory_order_relaxed);
for (int i = 0; i < N; i++) {
fExecutor.add([=] {
fn(i);
fPending.fetch_add(-1, sk_memory_order_release);
fPending.fetch_add(-1, std::memory_order_release);
});
}
}
@ -34,7 +34,7 @@ void SkTaskGroup::wait() {
// 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(sk_memory_order_acquire) > 0) {
while (fPending.load(std::memory_order_acquire) > 0) {
fExecutor.borrow();
}
}

View File

@ -8,9 +8,9 @@
#ifndef SkTaskGroup_DEFINED
#define SkTaskGroup_DEFINED
#include "SkAtomics.h"
#include "SkExecutor.h"
#include "SkTypes.h"
#include <atomic>
#include <functional>
class SkTaskGroup : SkNoncopyable {
@ -37,8 +37,8 @@ public:
};
private:
SkAtomic<int32_t> fPending;
SkExecutor& fExecutor;
std::atomic<int32_t> fPending;
SkExecutor& fExecutor;
};
#endif//SkTaskGroup_DEFINED