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

Issue 18770007: Add a 'unique' method to SkRefCnt, document the usage, and add support. (Closed)

Created:
7 years, 5 months ago by bungeman-skia
Modified:
7 years, 5 months ago
CC:
skia-review_googlegroups.com, dvykov_google.com
Visibility:
Public.

Description

Add a 'unique' method to SkRefCnt, document the usage, and add support. std::shared_ptr has a method called 'unique' which captures the concept that a reference count of 1 is special, and can be used to optimize copy on write. It also has some undocumented need for memory barriers in certain situations and those needs are documented here. The motivation for looking into this is crbug.com/258499 . The use of the reference count in this manner is a benign race with both ref() and unref(). By introducing sk_atomic_unprotected_read, it is possible for Chromium to annotate this read to tell ThreadSanitizer that this is known. R=bsalomon@google.com Committed: https://code.google.com/p/skia/source/detail?r=10221

Patch Set 1 #

Patch Set 2 : #

Total comments: 12

Patch Set 3 : Organize things so that they can be fixed. #

Patch Set 4 : Organize things so that they can be fixed. #

Patch Set 5 : Update comments. #

Unified diffs Side-by-side diffs Delta from patch set Stats (+36 lines, -34 lines) Patch
M include/core/SkRefCnt.h View 1 2 3 4 3 chunks +17 lines, -14 lines 0 comments Download
M src/core/SkPathRef.h View 1 2 3 chunks +12 lines, -11 lines 0 comments Download
M src/core/SkTRefArray.h View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/core/SkTypefaceCache.cpp View 1 2 1 chunk +1 line, -3 lines 0 comments Download
M src/gpu/GrContext.cpp View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/gpu/GrEffect.cpp View 1 2 1 chunk +1 line, -1 line 0 comments Download
M src/gpu/GrResourceCache.cpp View 1 2 2 chunks +2 lines, -2 lines 0 comments Download
M src/image/SkSurface.cpp View 1 2 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 10 (0 generated)
bungeman-skia
7 years, 5 months ago (2013-07-12 22:28:18 UTC) #1
bsalomon
mostly lgtm. Two questions inlined. https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode44 include/core/SkRefCnt.h:44: /** Return the reference ...
7 years, 5 months ago (2013-07-15 13:04:08 UTC) #2
Alexander Potapenko
https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode62 include/core/SkRefCnt.h:62: bool unique() const { I suggest to add an ...
7 years, 5 months ago (2013-07-15 15:05:34 UTC) #3
bungeman-skia
https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode44 include/core/SkRefCnt.h:44: /** Return the reference count. Use only for debugging. ...
7 years, 5 months ago (2013-07-15 16:02:40 UTC) #4
Dmitry Vyukov
https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode65 include/core/SkRefCnt.h:65: return (1 == sk_atomic_unprotected_read(fRefCnt)); sk_atomic_unprotected_read() needs to use Acquire_Load() ...
7 years, 5 months ago (2013-07-16 13:17:51 UTC) #5
Alexander Potapenko
https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode62 include/core/SkRefCnt.h:62: bool unique() const { Yes, I was talking about ...
7 years, 5 months ago (2013-07-16 14:03:30 UTC) #6
Dmitry Vyukov
https://codereview.chromium.org/18770007/diff/5003/src/core/SkPathRef.h File src/core/SkPathRef.h (right): https://codereview.chromium.org/18770007/diff/5003/src/core/SkPathRef.h#newcode43 src/core/SkPathRef.h:43: (*pathRef)->incReserve(incReserveVerbs, incReservePoints); Won't it be modified after this unique() ...
7 years, 5 months ago (2013-07-16 15:26:23 UTC) #7
bungeman-skia
https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h File include/core/SkRefCnt.h (right): https://codereview.chromium.org/18770007/diff/5003/include/core/SkRefCnt.h#newcode62 include/core/SkRefCnt.h:62: bool unique() const { On 2013/07/16 14:03:30, Alexander Potapenko ...
7 years, 5 months ago (2013-07-16 15:50:57 UTC) #8
bungeman-skia
So I have been convinced that even copy-on-write needs a L/S barrier after the read ...
7 years, 5 months ago (2013-07-19 19:24:15 UTC) #9
bungeman-skia
7 years, 5 months ago (2013-07-19 23:18:56 UTC) #10
Message was sent while issue was closed.
Committed patchset #5 manually as r10221.

Powered by Google App Engine
This is Rietveld 408576698