OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2015 Google Inc. | 2 * Copyright 2015 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #ifndef GrNonAtomicRef_DEFINED | 8 #ifndef GrNonAtomicRef_DEFINED |
9 #define GrNonAtomicRef_DEFINED | 9 #define GrNonAtomicRef_DEFINED |
10 | 10 |
(...skipping 10 matching lines...) Expand all Loading... |
21 | 21 |
22 #ifdef SK_DEBUG | 22 #ifdef SK_DEBUG |
23 ~GrNonAtomicRef() { | 23 ~GrNonAtomicRef() { |
24 // fRefCnt can be one when a subclass is created statically | 24 // fRefCnt can be one when a subclass is created statically |
25 SkASSERT((0 == fRefCnt || 1 == fRefCnt)); | 25 SkASSERT((0 == fRefCnt || 1 == fRefCnt)); |
26 // Set to invalid values. | 26 // Set to invalid values. |
27 fRefCnt = -10; | 27 fRefCnt = -10; |
28 } | 28 } |
29 #endif | 29 #endif |
30 | 30 |
| 31 bool unique() const { return 1 == fRefCnt; } |
| 32 |
31 void ref() const { | 33 void ref() const { |
32 // Once the ref cnt reaches zero it should never be ref'ed again. | 34 // Once the ref cnt reaches zero it should never be ref'ed again. |
33 SkASSERT(fRefCnt > 0); | 35 SkASSERT(fRefCnt > 0); |
34 ++fRefCnt; | 36 ++fRefCnt; |
35 } | 37 } |
36 | 38 |
37 void unref() const { | 39 void unref() const { |
38 SkASSERT(fRefCnt > 0); | 40 SkASSERT(fRefCnt > 0); |
39 --fRefCnt; | 41 --fRefCnt; |
40 if (0 == fRefCnt) { | 42 if (0 == fRefCnt) { |
41 GrTDeleteNonAtomicRef(static_cast<const TSubclass*>(this)); | 43 GrTDeleteNonAtomicRef(static_cast<const TSubclass*>(this)); |
42 return; | 44 return; |
43 } | 45 } |
44 } | 46 } |
45 | 47 |
46 private: | 48 private: |
47 mutable int32_t fRefCnt; | 49 mutable int32_t fRefCnt; |
48 | 50 |
49 typedef SkNoncopyable INHERITED; | 51 typedef SkNoncopyable INHERITED; |
50 }; | 52 }; |
51 | 53 |
52 template<typename T> inline void GrTDeleteNonAtomicRef(const T* ref) { | 54 template<typename T> inline void GrTDeleteNonAtomicRef(const T* ref) { |
53 delete ref; | 55 delete ref; |
54 } | 56 } |
55 | 57 |
56 #endif | 58 #endif |
OLD | NEW |