| 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 14 matching lines...) Expand all Loading... |
| 25 SkOnce(&st_once, add_five, &x); | 25 SkOnce(&st_once, add_five, &x); |
| 26 SkOnce(&st_once, add_five, &x); | 26 SkOnce(&st_once, add_five, &x); |
| 27 | 27 |
| 28 REPORTER_ASSERT(r, 5 == x); | 28 REPORTER_ASSERT(r, 5 == x); |
| 29 } | 29 } |
| 30 | 30 |
| 31 SK_DECLARE_STATIC_ONCE(mt_once); | 31 SK_DECLARE_STATIC_ONCE(mt_once); |
| 32 DEF_TEST(SkOnce_Multithreaded, r) { | 32 DEF_TEST(SkOnce_Multithreaded, r) { |
| 33 int x = 0; | 33 int x = 0; |
| 34 // Run a bunch of tasks to be the first to add six to x. | 34 // Run a bunch of tasks to be the first to add six to x. |
| 35 sk_parallel_for(1021, [&](int) { | 35 SkTaskGroup().batch(1021, [&](int) { |
| 36 void(*add_six)(int*) = [](int* p) { *p += 6; }; | 36 void(*add_six)(int*) = [](int* p) { *p += 6; }; |
| 37 SkOnce(&mt_once, add_six, &x); | 37 SkOnce(&mt_once, add_six, &x); |
| 38 }); | 38 }); |
| 39 | 39 |
| 40 // Only one should have done the +=. | 40 // Only one should have done the +=. |
| 41 REPORTER_ASSERT(r, 6 == x); | 41 REPORTER_ASSERT(r, 6 == x); |
| 42 } | 42 } |
| 43 | 43 |
| 44 static int gX = 0; | 44 static int gX = 0; |
| 45 static void inc_gX() { gX++; } | 45 static void inc_gX() { gX++; } |
| 46 | 46 |
| 47 SK_DECLARE_STATIC_ONCE(noarg_once); | 47 SK_DECLARE_STATIC_ONCE(noarg_once); |
| 48 DEF_TEST(SkOnce_NoArg, r) { | 48 DEF_TEST(SkOnce_NoArg, r) { |
| 49 SkOnce(&noarg_once, inc_gX); | 49 SkOnce(&noarg_once, inc_gX); |
| 50 SkOnce(&noarg_once, inc_gX); | 50 SkOnce(&noarg_once, inc_gX); |
| 51 SkOnce(&noarg_once, inc_gX); | 51 SkOnce(&noarg_once, inc_gX); |
| 52 REPORTER_ASSERT(r, 1 == gX); | 52 REPORTER_ASSERT(r, 1 == gX); |
| 53 } | 53 } |
| OLD | NEW |