OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2013 Google Inc. | 2 * Copyright 2013 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "SkOnce.h" | 8 #include "SkOnce.h" |
9 #include "SkRunnable.h" | 9 #include "SkRunnable.h" |
10 #include "SkTaskGroup.h" | 10 #include "SkTaskGroup.h" |
(...skipping 21 matching lines...) Expand all Loading... |
32 *x += 6; | 32 *x += 6; |
33 } | 33 } |
34 | 34 |
35 namespace { | 35 namespace { |
36 | 36 |
37 class Racer : public SkRunnable { | 37 class Racer : public SkRunnable { |
38 public: | 38 public: |
39 SkOnceFlag* once; | 39 SkOnceFlag* once; |
40 int* ptr; | 40 int* ptr; |
41 | 41 |
42 virtual void run() SK_OVERRIDE { | 42 void run() SK_OVERRIDE { |
43 SkOnce(once, add_six, ptr); | 43 SkOnce(once, add_six, ptr); |
44 } | 44 } |
45 }; | 45 }; |
46 | 46 |
47 } // namespace | 47 } // namespace |
48 | 48 |
49 DEF_TEST(SkOnce_Multithreaded, r) { | 49 DEF_TEST(SkOnce_Multithreaded, r) { |
50 const int kTasks = 16; | 50 const int kTasks = 16; |
51 | 51 |
52 // Make a bunch of tasks that will race to be the first to add six to x. | 52 // Make a bunch of tasks that will race to be the first to add six to x. |
(...skipping 19 matching lines...) Expand all Loading... |
72 static int gX = 0; | 72 static int gX = 0; |
73 static void inc_gX() { gX++; } | 73 static void inc_gX() { gX++; } |
74 | 74 |
75 DEF_TEST(SkOnce_NoArg, r) { | 75 DEF_TEST(SkOnce_NoArg, r) { |
76 SK_DECLARE_STATIC_ONCE(once); | 76 SK_DECLARE_STATIC_ONCE(once); |
77 SkOnce(&once, inc_gX); | 77 SkOnce(&once, inc_gX); |
78 SkOnce(&once, inc_gX); | 78 SkOnce(&once, inc_gX); |
79 SkOnce(&once, inc_gX); | 79 SkOnce(&once, inc_gX); |
80 REPORTER_ASSERT(r, 1 == gX); | 80 REPORTER_ASSERT(r, 1 == gX); |
81 } | 81 } |
OLD | NEW |