From 199ba8e19b0cafb37eea3beab162bc4b52728fff Mon Sep 17 00:00:00 2001 From: mtklein Date: Tue, 13 Jan 2015 08:40:23 -0800 Subject: namespace {} trick for SK_DECLARE_STATIC_ONCE Like all our other SK_DECLARE_STATIC_*, it's usually not a thread-safe thing to put inside a function. Adding namespace {} prevents that syntactically. Needs https://codereview.chromium.org/841263004/ to land first. BUG=chromium:447890 No public API changes. TBR=reed@google.com Review URL: https://codereview.chromium.org/806473006 --- tests/OnceTest.cpp | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'tests/OnceTest.cpp') diff --git a/tests/OnceTest.cpp b/tests/OnceTest.cpp index 6ab9cd27ac..1344cee5c4 100644 --- a/tests/OnceTest.cpp +++ b/tests/OnceTest.cpp @@ -14,16 +14,16 @@ static void add_five(int* x) { *x += 5; } +SK_DECLARE_STATIC_ONCE(st_once); DEF_TEST(SkOnce_Singlethreaded, r) { int x = 0; - SK_DECLARE_STATIC_ONCE(once); // No matter how many times we do this, x will be 5. - SkOnce(&once, add_five, &x); - SkOnce(&once, add_five, &x); - SkOnce(&once, add_five, &x); - SkOnce(&once, add_five, &x); - SkOnce(&once, add_five, &x); + SkOnce(&st_once, add_five, &x); + SkOnce(&st_once, add_five, &x); + SkOnce(&st_once, add_five, &x); + SkOnce(&st_once, add_five, &x); + SkOnce(&st_once, add_five, &x); REPORTER_ASSERT(r, 5 == x); } @@ -46,15 +46,15 @@ public: } // namespace +SK_DECLARE_STATIC_ONCE(mt_once); DEF_TEST(SkOnce_Multithreaded, r) { const int kTasks = 16; // Make a bunch of tasks that will race to be the first to add six to x. Racer racers[kTasks]; - SK_DECLARE_STATIC_ONCE(once); int x = 0; for (int i = 0; i < kTasks; i++) { - racers[i].once = &once; + racers[i].once = &mt_once; racers[i].ptr = &x; } @@ -72,10 +72,10 @@ DEF_TEST(SkOnce_Multithreaded, r) { static int gX = 0; static void inc_gX() { gX++; } +SK_DECLARE_STATIC_ONCE(noarg_once); DEF_TEST(SkOnce_NoArg, r) { - SK_DECLARE_STATIC_ONCE(once); - SkOnce(&once, inc_gX); - SkOnce(&once, inc_gX); - SkOnce(&once, inc_gX); + SkOnce(&noarg_once, inc_gX); + SkOnce(&noarg_once, inc_gX); + SkOnce(&noarg_once, inc_gX); REPORTER_ASSERT(r, 1 == gX); } -- cgit v1.2.3