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" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 // Let them race. | 70 // Let them race. |
71 SkThreadPool pool(kThreads); | 71 SkThreadPool pool(kThreads); |
72 for (int i = 0; i < kTasks; i++) { | 72 for (int i = 0; i < kTasks; i++) { |
73 pool.add(&racers[i]); | 73 pool.add(&racers[i]); |
74 } | 74 } |
75 pool.wait(); | 75 pool.wait(); |
76 | 76 |
77 // Only one should have done the +=. | 77 // Only one should have done the +=. |
78 REPORTER_ASSERT(r, 6 == x); | 78 REPORTER_ASSERT(r, 6 == x); |
79 } | 79 } |
| 80 |
| 81 // Test that the atExit option works. |
| 82 static int gToDecrement = 1; |
| 83 static void noop(int) {} |
| 84 static void decrement() { gToDecrement--; } |
| 85 static void checkDecremented() { SkASSERT(gToDecrement == 0); } |
| 86 |
| 87 DEF_TEST(SkOnce_atExit, r) { |
| 88 atexit(checkDecremented); |
| 89 SK_DECLARE_STATIC_ONCE(once); |
| 90 SkOnce(&once, noop, 0, decrement); |
| 91 } |
OLD | NEW |