Add sk_parallel_for()
authormtklein <mtklein@chromium.org>
Wed, 17 Jun 2015 22:26:15 +0000 (15:26 -0700)
committerCommit bot <commit-bot@chromium.org>
Wed, 17 Jun 2015 22:26:15 +0000 (15:26 -0700)
commit00b621cfc0dac2a0028757a974de33a78bb8579d
tree696d1a4560d37af4929a6d0501611ceb88c0b45e
parent5a9e2994c9915f76b1e3720f107e87fc952ffab2
Add sk_parallel_for()

This should be a drop-in replacement for most for-loops to make them run in parallel:
   for (int i = 0; i < N; i++) { code... }
   ~~~>
   sk_parallel_for(N, [&](int i) { code... });

This is just syntax sugar over SkTaskGroup to make this use case really easy to write.
There's no more overhead that we weren't already forced to add using an interface like batch(),
and no extra heap allocations.

I've replaced 3 uses of SkTaskGroup with sk_parallel_for:
  1) My unit tests for SkOnce.
  2) Cary's path fuzzer.
  3) SkMultiPictureDraw.
Performance should be the same.  Please compare left and right for readability. :)

BUG=skia:

No public API changes.
TBR=reed@google.com

Review URL: https://codereview.chromium.org/1184373003
12 files changed:
include/core/SkMultiPictureDraw.h
samplecode/SamplePathFuzz.cpp
src/core/SkMultiPictureDraw.cpp
src/core/SkTaskGroup.cpp
src/core/SkTaskGroup.h
tests/LazyPtrTest.cpp
tests/OnceTest.cpp
tests/PathOpsExtendedTest.cpp
tests/PathOpsSkpClipTest.cpp
tests/PathOpsThreadedCommon.cpp
tests/SkpSkGrTest.cpp
tools/skpdiff/SkDiffContext.cpp