OLD | NEW |
1 #include "Test.h" | 1 #include "Test.h" |
2 #include "SkLazyPtr.h" | 2 #include "SkLazyPtr.h" |
3 #include "SkRunnable.h" | 3 #include "SkRunnable.h" |
4 #include "SkTaskGroup.h" | 4 #include "SkTaskGroup.h" |
5 | 5 |
6 namespace { | 6 namespace { |
7 | 7 |
8 struct CreateIntFromFloat { | 8 struct CreateIntFromFloat { |
9 CreateIntFromFloat(float val) : fVal(val) {} | 9 CreateIntFromFloat(float val) : fVal(val) {} |
10 int* operator()() const { return SkNEW_ARGS(int, ((int)fVal)); } | 10 int* operator()() const { return SkNEW_ARGS(int, ((int)fVal)); } |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
42 REPORTER_ASSERT(r, 99 == *ptr); | 42 REPORTER_ASSERT(r, 99 == *ptr); |
43 // Since custom_destroy didn't actually delete ptr, we do now. | 43 // Since custom_destroy didn't actually delete ptr, we do now. |
44 SkDELETE(ptr); | 44 SkDELETE(ptr); |
45 } | 45 } |
46 | 46 |
47 namespace { | 47 namespace { |
48 | 48 |
49 struct Racer : public SkRunnable { | 49 struct Racer : public SkRunnable { |
50 Racer() : fLazy(NULL), fSeen(NULL) {} | 50 Racer() : fLazy(NULL), fSeen(NULL) {} |
51 | 51 |
52 void run() SK_OVERRIDE { fSeen = fLazy->get(); } | 52 void run() override { fSeen = fLazy->get(); } |
53 | 53 |
54 SkLazyPtr<int>* fLazy; | 54 SkLazyPtr<int>* fLazy; |
55 int* fSeen; | 55 int* fSeen; |
56 }; | 56 }; |
57 | 57 |
58 } // namespace | 58 } // namespace |
59 | 59 |
60 DEF_TEST(LazyPtr_Threaded, r) { | 60 DEF_TEST(LazyPtr_Threaded, r) { |
61 static const int kRacers = 321; | 61 static const int kRacers = 321; |
62 | 62 |
63 SkLazyPtr<int> lazy; | 63 SkLazyPtr<int> lazy; |
64 | 64 |
65 Racer racers[kRacers]; | 65 Racer racers[kRacers]; |
66 for (int i = 0; i < kRacers; i++) { | 66 for (int i = 0; i < kRacers; i++) { |
67 racers[i].fLazy = &lazy; | 67 racers[i].fLazy = &lazy; |
68 } | 68 } |
69 | 69 |
70 SkTaskGroup tg; | 70 SkTaskGroup tg; |
71 for (int i = 0; i < kRacers; i++) { | 71 for (int i = 0; i < kRacers; i++) { |
72 tg.add(racers + i); | 72 tg.add(racers + i); |
73 } | 73 } |
74 tg.wait(); | 74 tg.wait(); |
75 | 75 |
76 for (int i = 1; i < kRacers; i++) { | 76 for (int i = 1; i < kRacers; i++) { |
77 REPORTER_ASSERT(r, racers[i].fSeen); | 77 REPORTER_ASSERT(r, racers[i].fSeen); |
78 REPORTER_ASSERT(r, racers[i].fSeen == racers[0].fSeen); | 78 REPORTER_ASSERT(r, racers[i].fSeen == racers[0].fSeen); |
79 } | 79 } |
80 } | 80 } |
OLD | NEW |