OLD | NEW |
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 Loading... |
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 | |
46 /** Return the reference count. Use only for debugging. */ | 45 /** Return the reference count. Use only for debugging. */ |
47 int32_t getRefCnt() const { return fRefCnt; } | 46 int32_t getRefCnt() const { return fRefCnt; } |
48 #endif | |
49 | 47 |
50 /** May return true if the caller is the only owner. | 48 /** May return true if the caller is the only owner. |
51 * Ensures that all previous owner's actions are complete. | 49 * Ensures that all previous owner's actions are complete. |
52 */ | 50 */ |
53 bool unique() const { | 51 bool unique() const { |
54 // We believe we're reading fRefCnt in a safe way here, so we stifle the
TSAN warning about | 52 // 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. | 53 // an unproctected read. Generally, don't read fRefCnt, and don't stifl
e this warning. |
56 bool const unique = (1 == SK_ANNOTATE_UNPROTECTED_READ(fRefCnt)); | 54 bool const unique = (1 == SK_ANNOTATE_UNPROTECTED_READ(fRefCnt)); |
57 if (unique) { | 55 if (unique) { |
58 // Acquire barrier (L/SL), if not provided by load of fRefCnt. | 56 // Acquire barrier (L/SL), if not provided by load of fRefCnt. |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 SkDELETE(this); | 111 SkDELETE(this); |
114 } | 112 } |
115 | 113 |
116 // The following friends are those which override internal_dispose() | 114 // The following friends are those which override internal_dispose() |
117 // and conditionally call SkRefCnt::internal_dispose(). | 115 // and conditionally call SkRefCnt::internal_dispose(). |
118 friend class GrTexture; | 116 friend class GrTexture; |
119 friend class SkWeakRefCnt; | 117 friend class SkWeakRefCnt; |
120 | 118 |
121 mutable int32_t fRefCnt; | 119 mutable int32_t fRefCnt; |
122 | 120 |
123 // Used by tests. | |
124 friend bool RefCntIs(const SkRefCntBase&, int32_t); | |
125 | |
126 typedef SkNoncopyable INHERITED; | 121 typedef SkNoncopyable INHERITED; |
127 }; | 122 }; |
128 | 123 |
129 #ifdef SK_REF_CNT_MIXIN_INCLUDE | 124 #ifdef SK_REF_CNT_MIXIN_INCLUDE |
130 // It is the responsibility of the following include to define the type SkRefCnt
. | 125 // It is the responsibility of the following include to define the type SkRefCnt
. |
131 // This SkRefCnt should normally derive from SkRefCntBase. | 126 // This SkRefCnt should normally derive from SkRefCntBase. |
132 #include SK_REF_CNT_MIXIN_INCLUDE | 127 #include SK_REF_CNT_MIXIN_INCLUDE |
133 #else | 128 #else |
134 class SK_API SkRefCnt : public SkRefCntBase { }; | 129 class SK_API SkRefCnt : public SkRefCntBase { }; |
135 #endif | 130 #endif |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 typedef T* SkRefPtr::*unspecified_bool_type; | 283 typedef T* SkRefPtr::*unspecified_bool_type; |
289 operator unspecified_bool_type() const { | 284 operator unspecified_bool_type() const { |
290 return fObj ? &SkRefPtr::fObj : NULL; | 285 return fObj ? &SkRefPtr::fObj : NULL; |
291 } | 286 } |
292 | 287 |
293 private: | 288 private: |
294 T* fObj; | 289 T* fObj; |
295 }; | 290 }; |
296 | 291 |
297 #endif | 292 #endif |
OLD | NEW |