diff options
author | mtklein <mtklein@chromium.org> | 2016-04-18 08:09:11 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-04-18 08:09:11 -0700 |
commit | d9dd4282118fc14eac735e6fa0b3ec53047b457f (patch) | |
tree | b88bce11cbcec3100e428b713df49e1fcd83f8d2 /tests | |
parent | f7142e71d7c0a7d8406679e207ff766085499d2e (diff) |
Modernize and trim down SkOnce.
The API and implementation are very much simplified.
You may not want to bother reading the diff.
As is our trend, SkOnce now uses <atomic> directly.
Member initialization means we don't need SK_DECLARE_STATIC_ONCE.
SkSpinlock already works this same way.
All uses of the old API taking an external bool* and Lock* were pessimal,
so I have not carried this sort of API forward. It's simpler, faster,
and more space-efficient to always use this single SkOnce class interface.
SkOnce weighs 2 bytes: a done bool and an SkSpinlock, also a bool internally.
This API refactoring opens up the opportunity to fuse those into a single
three-state byte if we'd like.
No public API changes.
TBR=reed@google.com
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1894893002
Review URL: https://codereview.chromium.org/1894893002
Diffstat (limited to 'tests')
-rw-r--r-- | tests/OnceTest.cpp | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/tests/OnceTest.cpp b/tests/OnceTest.cpp index 83ee66b6c8..ef8d3d9225 100644 --- a/tests/OnceTest.cpp +++ b/tests/OnceTest.cpp @@ -13,27 +13,27 @@ static void add_five(int* x) { *x += 5; } -SK_DECLARE_STATIC_ONCE(st_once); DEF_TEST(SkOnce_Singlethreaded, r) { int x = 0; // No matter how many times we do this, x will be 5. - 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); + SkOnce once; + once(add_five, &x); + once(add_five, &x); + once(add_five, &x); + once(add_five, &x); + once(add_five, &x); REPORTER_ASSERT(r, 5 == x); } -SK_DECLARE_STATIC_ONCE(mt_once); DEF_TEST(SkOnce_Multithreaded, r) { int x = 0; + // Run a bunch of tasks to be the first to add six to x. + SkOnce once; SkTaskGroup().batch(1021, [&](int) { - void(*add_six)(int*) = [](int* p) { *p += 6; }; - SkOnce(&mt_once, add_six, &x); + once([&] { x += 6; }); }); // Only one should have done the +=. @@ -43,10 +43,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) { - SkOnce(&noarg_once, inc_gX); - SkOnce(&noarg_once, inc_gX); - SkOnce(&noarg_once, inc_gX); + SkOnce once; + once(inc_gX); + once(inc_gX); + once(inc_gX); REPORTER_ASSERT(r, 1 == gX); } |