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" | |
10 #include "SkThreadPool.h" | 9 #include "SkThreadPool.h" |
11 #include "Test.h" | 10 #include "Test.h" |
12 #include "TestClassDef.h" | 11 #include "TestClassDef.h" |
13 | 12 |
14 DEF_SK_ONCE(add_five, int* x) { | 13 DEF_SK_ONCE(add_five, int* x) { |
15 *x += 5; | 14 *x += 5; |
16 } | 15 } |
17 | 16 |
18 DEF_TEST(SkOnce_Singlethreaded, r) { | 17 DEF_TEST(SkOnce_Singlethreaded, r) { |
19 int x = 0; | 18 int x = 0; |
(...skipping 29 matching lines...) Expand all Loading... |
49 const int kTasks = 16, kThreads = 4; | 48 const int kTasks = 16, kThreads = 4; |
50 | 49 |
51 // Make a bunch of tasks that will race to be the first to add six to x. | 50 // Make a bunch of tasks that will race to be the first to add six to x. |
52 Racer racers[kTasks]; | 51 Racer racers[kTasks]; |
53 int x = 0; | 52 int x = 0; |
54 for (int i = 0; i < kTasks; i++) { | 53 for (int i = 0; i < kTasks; i++) { |
55 racers[i].ptr = &x; | 54 racers[i].ptr = &x; |
56 } | 55 } |
57 | 56 |
58 // Let them race. | 57 // Let them race. |
59 SkAutoTDelete<SkThreadPool> pool(new SkThreadPool(kThreads)); | 58 SkThreadPool pool(kThreads); |
60 for (int i = 0; i < kTasks; i++) { | 59 for (int i = 0; i < kTasks; i++) { |
61 pool->add(&racers[i]); | 60 pool.add(&racers[i]); |
62 } | 61 } |
63 pool.free(); // Blocks until all threads are done. | 62 pool.wait(); |
64 | 63 |
65 // Only one should have done the +=. | 64 // Only one should have done the +=. |
66 REPORTER_ASSERT(r, 6 == x); | 65 REPORTER_ASSERT(r, 6 == x); |
67 } | 66 } |
OLD | NEW |