OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 SkRefCnt_DEFINED | 8 #ifndef SkRefCnt_DEFINED |
9 #define SkRefCnt_DEFINED | 9 #define SkRefCnt_DEFINED |
10 | 10 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 fRefCnt = 1; | 102 fRefCnt = 1; |
103 #endif | 103 #endif |
104 } | 104 } |
105 | 105 |
106 private: | 106 private: |
107 /** | 107 /** |
108 * Called when the ref count goes to 0. | 108 * Called when the ref count goes to 0. |
109 */ | 109 */ |
110 virtual void internal_dispose() const { | 110 virtual void internal_dispose() const { |
111 this->internal_dispose_restore_refcnt_to_1(); | 111 this->internal_dispose_restore_refcnt_to_1(); |
112 SkDELETE(this); | 112 delete this; |
113 } | 113 } |
114 | 114 |
115 // The following friends are those which override internal_dispose() | 115 // The following friends are those which override internal_dispose() |
116 // and conditionally call SkRefCnt::internal_dispose(). | 116 // and conditionally call SkRefCnt::internal_dispose(). |
117 friend class SkWeakRefCnt; | 117 friend class SkWeakRefCnt; |
118 | 118 |
119 mutable int32_t fRefCnt; | 119 mutable int32_t fRefCnt; |
120 | 120 |
121 typedef SkNoncopyable INHERITED; | 121 typedef SkNoncopyable INHERITED; |
122 }; | 122 }; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
235 | 235 |
236 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: | 236 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: |
237 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; | 237 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; |
238 // - ref() doesn't need any barrier; | 238 // - ref() doesn't need any barrier; |
239 // - unref() needs a release barrier, and an acquire if it's going to call
delete. | 239 // - unref() needs a release barrier, and an acquire if it's going to call
delete. |
240 | 240 |
241 bool unique() const { return 1 == sk_atomic_load(&fRefCnt, sk_memory_order_a
cquire); } | 241 bool unique() const { return 1 == sk_atomic_load(&fRefCnt, sk_memory_order_a
cquire); } |
242 void ref() const { (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_orde
r_relaxed); } | 242 void ref() const { (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_orde
r_relaxed); } |
243 void unref() const { | 243 void unref() const { |
244 if (1 == sk_atomic_fetch_add(&fRefCnt, -1, sk_memory_order_acq_rel)) { | 244 if (1 == sk_atomic_fetch_add(&fRefCnt, -1, sk_memory_order_acq_rel)) { |
245 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's as
sert | 245 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's ass
ert |
246 SkDELETE((const Derived*)this); | 246 delete (const Derived*)this; |
247 } | 247 } |
248 } | 248 } |
249 void deref() const { this->unref(); } | 249 void deref() const { this->unref(); } |
250 | 250 |
251 private: | 251 private: |
252 mutable int32_t fRefCnt; | 252 mutable int32_t fRefCnt; |
253 }; | 253 }; |
254 | 254 |
255 #endif | 255 #endif |
OLD | NEW |