From 1b81877880253c75f835eede9a8ee21b9e7b584a Mon Sep 17 00:00:00 2001 From: mtklein Date: Mon, 2 Jun 2014 11:26:59 -0700 Subject: Clean up SkOnce: 1 Remove atExit feature: clients can do it just as well as SkOnce can. 2 Remove support for functors: no one but the unit test did that. 3 Remove support for unused non-static SkOnceFlag (no SK_ONCE_INIT). 4 Add SkOnce variants for no-arg functions so we're not forced to pass dummy values all the time. 5 Merge SkSpinlock and SkOnceFlag, making all members private. 6 More notes about memory barriers, adding an acquire load after acquiring the spinlock. BUG=skia: R=bungeman@google.com, mtklein@google.com, reed@google.com Author: mtklein@chromium.org Review URL: https://codereview.chromium.org/302083003 --- tests/OnceTest.cpp | 29 +++++++---------------------- 1 file changed, 7 insertions(+), 22 deletions(-) (limited to 'tests/OnceTest.cpp') diff --git a/tests/OnceTest.cpp b/tests/OnceTest.cpp index 3a99c39d53..389d257b73 100644 --- a/tests/OnceTest.cpp +++ b/tests/OnceTest.cpp @@ -27,20 +27,6 @@ DEF_TEST(SkOnce_Singlethreaded, r) { REPORTER_ASSERT(r, 5 == x); } -struct AddFour { void operator()(int* x) { *x += 4; } }; - -DEF_TEST(SkOnce_MiscFeatures, r) { - // Tests that we support functors and explicit SkOnceFlags. - int x = 0; - - SkOnceFlag once = SK_ONCE_INIT; - SkOnce(&once, AddFour(), &x); - SkOnce(&once, AddFour(), &x); - SkOnce(&once, AddFour(), &x); - - REPORTER_ASSERT(r, 4 == x); -} - static void add_six(int* x) { *x += 6; } @@ -78,14 +64,13 @@ DEF_TEST(SkOnce_Multithreaded, r) { REPORTER_ASSERT(r, 6 == x); } -// Test that the atExit option works. -static int gToDecrement = 1; -static void noop(int) {} -static void decrement() { gToDecrement--; } -static void checkDecremented() { SkASSERT(gToDecrement == 0); } +static int gX = 0; +static void inc_gX() { gX++; } -DEF_TEST(SkOnce_atExit, r) { - atexit(checkDecremented); +DEF_TEST(SkOnce_NoArg, r) { SK_DECLARE_STATIC_ONCE(once); - SkOnce(&once, noop, 0, decrement); + SkOnce(&once, inc_gX); + SkOnce(&once, inc_gX); + SkOnce(&once, inc_gX); + REPORTER_ASSERT(r, 1 == gX); } -- cgit v1.2.3