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

Unified Diff: tests/LazyPtrTest.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 | « src/core/SkTaskGroup.cpp ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/LazyPtrTest.cpp
diff --git a/tests/LazyPtrTest.cpp b/tests/LazyPtrTest.cpp
index 1b845bc502777c361782694ba4ed539acad44b83..89443f9a808e7cafd5291e4e42b0604e162aa4ad 100644
--- a/tests/LazyPtrTest.cpp
+++ b/tests/LazyPtrTest.cpp
@@ -1,3 +1,10 @@
+/*
+ * Copyright 2014 Google Inc.
+ *
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
#include "Test.h"
#include "SkLazyPtr.h"
#include "SkRunnable.h"
@@ -44,37 +51,20 @@ DEF_TEST(LazyPtr, r) {
SkDELETE(ptr);
}
-namespace {
-
-struct Racer : public SkRunnable {
- Racer() : fLazy(NULL), fSeen(NULL) {}
-
- void run() override { fSeen = fLazy->get(); }
-
- SkLazyPtr<int>* fLazy;
- int* fSeen;
-};
-
-} // namespace
-
DEF_TEST(LazyPtr_Threaded, r) {
static const int kRacers = 321;
+ // Race to intialize the pointer by calling .get().
SkLazyPtr<int> lazy;
+ int* seen[kRacers];
- Racer racers[kRacers];
- for (int i = 0; i < kRacers; i++) {
- racers[i].fLazy = &lazy;
- }
-
- SkTaskGroup tg;
- for (int i = 0; i < kRacers; i++) {
- tg.add(racers + i);
- }
- tg.wait();
+ sk_parallel_for(kRacers, [&](int i) {
+ seen[i] = lazy.get();
+ });
+ // lazy.get() should return the same pointer to all threads.
for (int i = 1; i < kRacers; i++) {
- REPORTER_ASSERT(r, racers[i].fSeen);
- REPORTER_ASSERT(r, racers[i].fSeen == racers[0].fSeen);
+ REPORTER_ASSERT(r, seen[i] != nullptr);
+ REPORTER_ASSERT(r, seen[i] == seen[0]);
}
}
« no previous file with comments | « src/core/SkTaskGroup.cpp ('k') | tests/OnceTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698