OLD | NEW |
| (Empty) |
1 #include "Test.h" | |
2 #include "SkLazyPtr.h" | |
3 #include "SkTaskGroup.h" | |
4 | |
5 DEF_TEST(LazyPtr, r) { | |
6 SkLazyPtr<int> lazy; | |
7 int* ptr = lazy.get(); | |
8 | |
9 REPORTER_ASSERT(r, ptr); | |
10 REPORTER_ASSERT(r, lazy.get() == ptr); | |
11 | |
12 SkLazyPtr<double> neverRead; | |
13 } | |
14 | |
15 namespace { | |
16 | |
17 struct Racer : public SkRunnable { | |
18 Racer() : fLazy(NULL), fSeen(NULL) {} | |
19 | |
20 virtual void run() SK_OVERRIDE { fSeen = fLazy->get(); } | |
21 | |
22 SkLazyPtr<int>* fLazy; | |
23 int* fSeen; | |
24 }; | |
25 | |
26 } // namespace | |
27 | |
28 DEF_TEST(LazyPtr_Threaded, r) { | |
29 static const int kRacers = 321; | |
30 | |
31 SkLazyPtr<int> lazy; | |
32 | |
33 Racer racers[kRacers]; | |
34 for (int i = 0; i < kRacers; i++) { | |
35 racers[i].fLazy = &lazy; | |
36 } | |
37 | |
38 SkTaskGroup tg; | |
39 for (int i = 0; i < kRacers; i++) { | |
40 tg.add(racers + i); | |
41 } | |
42 tg.wait(); | |
43 | |
44 for (int i = 1; i < kRacers; i++) { | |
45 REPORTER_ASSERT(r, racers[i].fSeen); | |
46 REPORTER_ASSERT(r, racers[i].fSeen == racers[0].fSeen); | |
47 } | |
48 } | |
OLD | NEW |