Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(316)

Issue 1894893002: Modernize and trim down SkOnce. (Closed)

Created:
4 years, 8 months ago by mtklein_C
Modified:
4 years, 8 months ago
CC:
reviews_skia.org
Base URL:
https://skia.googlesource.com/skia.git@master
Target Ref:
refs/heads/master
Project:
skia
Visibility:
Public.

Description

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 Committed: https://skia.googlesource.com/skia/+/d9dd4282118fc14eac735e6fa0b3ec53047b457f

Patch Set 1 #

Patch Set 2 : might as well class #

Total comments: 5
Unified diffs Side-by-side diffs Delta from patch set Stats (+65 lines, -167 lines) Patch
M include/effects/SkColorCubeFilter.h View 2 chunks +2 lines, -3 lines 0 comments Download
M include/gpu/GrResourceKey.h View 2 chunks +3 lines, -3 lines 0 comments Download
M include/ports/SkFontMgr_indirect.h View 3 chunks +3 lines, -3 lines 0 comments Download
M include/private/SkOnce.h View 1 1 chunk +21 lines, -120 lines 3 comments Download
M src/core/SkGlobalInitialization_core.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
M src/core/SkOpts.cpp View 1 chunk +4 lines, -2 lines 0 comments Download
M src/core/SkTaskGroup.cpp View 1 chunk +3 lines, -3 lines 2 comments Download
M src/effects/SkColorCubeFilter.cpp View 2 chunks +3 lines, -4 lines 0 comments Download
M src/effects/gradients/SkGradientShader.cpp View 3 chunks +2 lines, -6 lines 0 comments Download
M src/effects/gradients/SkGradientShaderPriv.h View 1 chunk +2 lines, -2 lines 0 comments Download
M src/fonts/SkFontMgr_indirect.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
M src/gpu/GrProgramElement.cpp View 1 chunk +1 line, -0 lines 0 comments Download
M src/utils/win/SkDWrite.cpp View 1 chunk +2 lines, -2 lines 0 comments Download
M tests/OnceTest.cpp View 2 chunks +13 lines, -13 lines 0 comments Download
M tools/gpu/gl/command_buffer/GLTestContext_command_buffer.cpp View 1 chunk +2 lines, -2 lines 0 comments Download

Messages

Total messages: 23 (12 generated)
commit-bot: I haz the power
Dry run: CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1894893002/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1894893002/20001
4 years, 8 months ago (2016-04-17 15:17:46 UTC) #6
mtklein_C
4 years, 8 months ago (2016-04-17 15:28:19 UTC) #10
herb_g
https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h File include/private/SkOnce.h (right): https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h#newcode29 include/private/SkOnce.h:29: fDone.store(true, std::memory_order_release); Should the memory release from the spinlock ...
4 years, 8 months ago (2016-04-18 14:29:51 UTC) #11
mtklein
https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h File include/private/SkOnce.h (right): https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h#newcode29 include/private/SkOnce.h:29: fDone.store(true, std::memory_order_release); On 2016/04/18 at 14:29:51, herb_g wrote: > ...
4 years, 8 months ago (2016-04-18 14:41:23 UTC) #13
herb_g
lgtm https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h File include/private/SkOnce.h (right): https://codereview.chromium.org/1894893002/diff/20001/include/private/SkOnce.h#newcode29 include/private/SkOnce.h:29: fDone.store(true, std::memory_order_release); On 2016/04/18 14:41:23, mtklein wrote: > ...
4 years, 8 months ago (2016-04-18 14:53:10 UTC) #14
commit-bot: I haz the power
CQ is trying da patch. Follow status at https://chromium-cq-status.appspot.com/patch-status/1894893002/20001 View timeline at https://chromium-cq-status.appspot.com/patch-timeline/1894893002/20001
4 years, 8 months ago (2016-04-18 15:07:55 UTC) #17
commit-bot: I haz the power
Committed patchset #2 (id:20001) as https://skia.googlesource.com/skia/+/d9dd4282118fc14eac735e6fa0b3ec53047b457f
4 years, 8 months ago (2016-04-18 15:09:14 UTC) #19
bungeman-skia
https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp File src/core/SkTaskGroup.cpp (right): https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp#newcode32 src/core/SkTaskGroup.cpp:32: static SkOnce once; It is not entirely clear to ...
4 years, 8 months ago (2016-04-18 15:19:00 UTC) #20
mtklein
https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp File src/core/SkTaskGroup.cpp (right): https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp#newcode32 src/core/SkTaskGroup.cpp:32: static SkOnce once; On 2016/04/18 at 15:19:00, bungeman1 wrote: ...
4 years, 8 months ago (2016-04-18 15:27:44 UTC) #21
bungeman-skia
On 2016/04/18 15:27:44, mtklein wrote: > https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp > File src/core/SkTaskGroup.cpp (right): > > https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp#newcode32 > ...
4 years, 8 months ago (2016-04-18 15:44:33 UTC) #22
mtklein
4 years, 8 months ago (2016-04-18 16:40:18 UTC) #23
Message was sent while issue was closed.
On 2016/04/18 at 15:44:33, bungeman wrote:
> On 2016/04/18 15:27:44, mtklein wrote:
> >
https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cpp
> > File src/core/SkTaskGroup.cpp (right):
> > 
> >
https://codereview.chromium.org/1894893002/diff/20001/src/core/SkTaskGroup.cp...
> > src/core/SkTaskGroup.cpp:32: static SkOnce once;
> > On 2016/04/18 at 15:19:00, bungeman1 wrote:
> > > It is not entirely clear to me how using member initializers solves the
issue
> > of initializing this value.
> > 
> > It makes the default constructor for SkOnce constexpr.  The SkOnce comes
> > pre-initialized.
> 
> Hmmm... yes. Can we state that constraint explicitly both here and in
SkSpinlock, like
> 
> constexpr SkOnce() = default;
> 
> We're relying on this for correctness, so it would be nice to be explicit
about it and have the compiler yell at anyone who violates it.
> 
> Of course, we can't while supporting vs2013 because this won't compile there
(I think). So on vs2013 this is racy if thread safe statics are turned off, but
we claim not to have any customers that need that anymore? Once we don't care to
build on vs2013 at all, we can mark the default constructor explicitly as
constexpr though.

Yep, generally agreed.  I would very much like to write constexpr SkOnce() =
default, and constexpr SkSpinlock() = default, and one day constexpr SkMutex() =
default, constexpr SkSemaphore() = default, etc.  I don't even particularly care
so much about the = default once we can sanely write constexpr.

I have not confirmed one way or the other if vs2013 compiles this as racy
runtime code or as pre-intialized.  At this point we're just catching up with
customers already on 2015.

Powered by Google App Engine
This is Rietveld 408576698