Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1483)

Unified Diff: tests/OnceTest.cpp

Issue 1184373003: Add sk_parallel_for() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: fix Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/LazyPtrTest.cpp ('k') | tests/PathOpsExtendedTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/OnceTest.cpp
diff --git a/tests/OnceTest.cpp b/tests/OnceTest.cpp
index 034c5d912f953705926d5ea19961627966730db7..35c2015166b98e9209ad9cf8fbf4aa858d65815f 100644
--- a/tests/OnceTest.cpp
+++ b/tests/OnceTest.cpp
@@ -28,42 +28,14 @@ DEF_TEST(SkOnce_Singlethreaded, r) {
REPORTER_ASSERT(r, 5 == x);
}
-static void add_six(int* x) {
- *x += 6;
-}
-
-namespace {
-
-class Racer : public SkRunnable {
-public:
- SkOnceFlag* once;
- int* ptr;
-
- void run() override {
- SkOnce(once, add_six, ptr);
- }
-};
-
-} // namespace
-
SK_DECLARE_STATIC_ONCE(mt_once);
DEF_TEST(SkOnce_Multithreaded, r) {
- const int kTasks = 16;
-
- // Make a bunch of tasks that will race to be the first to add six to x.
- Racer racers[kTasks];
int x = 0;
- for (int i = 0; i < kTasks; i++) {
- racers[i].once = &mt_once;
- racers[i].ptr = &x;
- }
-
- // Let them race.
- SkTaskGroup tg;
- for (int i = 0; i < kTasks; i++) {
- tg.add(&racers[i]);
- }
- tg.wait();
+ // Run a bunch of tasks to be the first to add six to x.
+ sk_parallel_for(1021, [&](int) {
+ void(*add_six)(int*) = [](int* p) { *p += 6; };
+ SkOnce(&mt_once, add_six, &x);
+ });
// Only one should have done the +=.
REPORTER_ASSERT(r, 6 == x);
« no previous file with comments | « tests/LazyPtrTest.cpp ('k') | tests/PathOpsExtendedTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698