| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: | 211 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: |
| 212 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; | 212 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; |
| 213 // - ref() doesn't need any barrier; | 213 // - ref() doesn't need any barrier; |
| 214 // - unref() needs a release barrier, and an acquire if it's going to call
delete. | 214 // - unref() needs a release barrier, and an acquire if it's going to call
delete. |
| 215 | 215 |
| 216 bool unique() const { return 1 == sk_atomic_load(&fRefCnt, sk_memory_order_a
cquire); } | 216 bool unique() const { return 1 == sk_atomic_load(&fRefCnt, sk_memory_order_a
cquire); } |
| 217 void ref() const { (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_orde
r_relaxed); } | 217 void ref() const { (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_orde
r_relaxed); } |
| 218 void unref() const { | 218 void unref() const { |
| 219 if (1 == sk_atomic_fetch_add(&fRefCnt, -1, sk_memory_order_acq_rel)) { | 219 if (1 == sk_atomic_fetch_add(&fRefCnt, -1, sk_memory_order_acq_rel)) { |
| 220 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's ass
ert | 220 SkDEBUGCODE(fRefCnt = 1;) // restore the 1 for our destructor's ass
ert |
| 221 delete (const Derived*)this; | 221 delete (const Derived*)this; |
| 222 } | 222 } |
| 223 } | 223 } |
| 224 void deref() const { this->unref(); } | 224 void deref() const { this->unref(); } |
| 225 | 225 |
| 226 private: | 226 private: |
| 227 mutable int32_t fRefCnt; | 227 mutable int32_t fRefCnt; |
| 228 }; | 228 }; |
| 229 | 229 |
| 230 #endif | 230 #endif |
| OLD | NEW |