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

Side by Side Diff: include/core/SkRefCnt.h

Issue 758693002: Blink hasn't rolled yet, better. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 1
2 /* 2 /*
3 * Copyright 2006 The Android Open Source Project 3 * Copyright 2006 The Android Open Source Project
4 * 4 *
5 * Use of this source code is governed by a BSD-style license that can be 5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file. 6 * found in the LICENSE file.
7 */ 7 */
8 8
9 9
10 #ifndef SkRefCnt_DEFINED 10 #ifndef SkRefCnt_DEFINED
(...skipping 24 matching lines...) Expand all
35 35
36 /** Destruct, asserting that the reference count is 1. 36 /** Destruct, asserting that the reference count is 1.
37 */ 37 */
38 virtual ~SkRefCntBase() { 38 virtual ~SkRefCntBase() {
39 #ifdef SK_DEBUG 39 #ifdef SK_DEBUG
40 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); 40 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt);
41 fRefCnt = 0; // illegal value, to catch us if we reuse after delete 41 fRefCnt = 0; // illegal value, to catch us if we reuse after delete
42 #endif 42 #endif
43 } 43 }
44 44
45 #ifdef SK_DEBUG 45 //#ifdef SK_DEBUG
46 /** Return the reference count. Use only for debugging. */ 46 /** Return the reference count. Use only for debugging. */
47 int32_t getRefCnt() const { return fRefCnt; } 47 int32_t getRefCnt() const { return fRefCnt; }
48 #endif 48 //#endif
49 49
50 /** May return true if the caller is the only owner. 50 /** May return true if the caller is the only owner.
51 * Ensures that all previous owner's actions are complete. 51 * Ensures that all previous owner's actions are complete.
52 */ 52 */
53 bool unique() const { 53 bool unique() const {
54 // We believe we're reading fRefCnt in a safe way here, so we stifle the TSAN warning about 54 // We believe we're reading fRefCnt in a safe way here, so we stifle the TSAN warning about
55 // an unproctected read. Generally, don't read fRefCnt, and don't stifl e this warning. 55 // an unproctected read. Generally, don't read fRefCnt, and don't stifl e this warning.
56 bool const unique = (1 == sk_acquire_load(&fRefCnt)); 56 bool const unique = (1 == sk_acquire_load(&fRefCnt));
57 if (unique) { 57 if (unique) {
58 // Acquire barrier (L/SL), if not provided by load of fRefCnt. 58 // Acquire barrier (L/SL), if not provided by load of fRefCnt.
(...skipping 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 void ref() const { sk_atomic_inc(&fRefCnt); } 266 void ref() const { sk_atomic_inc(&fRefCnt); }
267 void unref() const { 267 void unref() const {
268 int32_t prevValue = sk_atomic_dec(&fRefCnt); 268 int32_t prevValue = sk_atomic_dec(&fRefCnt);
269 SkASSERT(prevValue >= 1); 269 SkASSERT(prevValue >= 1);
270 if (1 == prevValue) { 270 if (1 == prevValue) {
271 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's as sert 271 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's as sert
272 SkDELETE((const Derived*)this); 272 SkDELETE((const Derived*)this);
273 } 273 }
274 } 274 }
275 void deref() const { this->unref(); } // Chrome prefers to call deref(). 275 void deref() const { this->unref(); } // Chrome prefers to call deref().
276 int32_t getRefCnt() const { return fRefCnt; }
276 277
277 private: 278 private:
278 mutable int32_t fRefCnt; 279 mutable int32_t fRefCnt;
279 }; 280 };
280 281
281 #endif 282 #endif
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698