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 "SkThreadPool.h" | 9 #include "SkThreadPool.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 #include "TestClassDef.h" | |
12 | 11 |
13 static void add_five(int* x) { | 12 static void add_five(int* x) { |
14 *x += 5; | 13 *x += 5; |
15 } | 14 } |
16 | 15 |
17 DEF_TEST(SkOnce_Singlethreaded, r) { | 16 DEF_TEST(SkOnce_Singlethreaded, r) { |
18 int x = 0; | 17 int x = 0; |
19 | 18 |
20 SK_DECLARE_STATIC_ONCE(once); | 19 SK_DECLARE_STATIC_ONCE(once); |
21 // No matter how many times we do this, x will be 5. | 20 // No matter how many times we do this, x will be 5. |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 // Let them race. | 70 // Let them race. |
72 SkThreadPool pool(kThreads); | 71 SkThreadPool pool(kThreads); |
73 for (int i = 0; i < kTasks; i++) { | 72 for (int i = 0; i < kTasks; i++) { |
74 pool.add(&racers[i]); | 73 pool.add(&racers[i]); |
75 } | 74 } |
76 pool.wait(); | 75 pool.wait(); |
77 | 76 |
78 // Only one should have done the +=. | 77 // Only one should have done the +=. |
79 REPORTER_ASSERT(r, 6 == x); | 78 REPORTER_ASSERT(r, 6 == x); |
80 } | 79 } |
OLD | NEW |