| 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 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 254 public: | 254 public: |
| 255 SkNVRefCnt() : fRefCnt(1) {} | 255 SkNVRefCnt() : fRefCnt(1) {} |
| 256 | 256 |
| 257 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: | 257 // Implementation is pretty much the same as SkRefCntBase. All required barr
iers are the same: |
| 258 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; | 258 // - unique() needs acquire when it returns true, and no barrier if it ret
urns false; |
| 259 // - ref() doesn't need any barrier; | 259 // - ref() doesn't need any barrier; |
| 260 // - unref() needs a release barrier, and an acquire if it's going to call
delete. | 260 // - unref() needs a release barrier, and an acquire if it's going to call
delete. |
| 261 | 261 |
| 262 bool unique() const { return 1 == sk_acquire_load(&fRefCnt); } | 262 bool unique() const { return 1 == sk_acquire_load(&fRefCnt); } |
| 263 void ref() const { sk_atomic_inc(&fRefCnt); } | 263 void ref() const { sk_atomic_inc(&fRefCnt); } |
| 264 void unref() const { if (1 == sk_atomic_dec(&fRefCnt)) { SkDELETE((const De
rived*)this); } } | 264 void unref() const { |
| 265 int32_t prevValue = sk_atomic_dec(&fRefCnt); |
| 266 SkASSERT(prevValue >= 1); |
| 267 if (1 == prevValue) { |
| 268 SkDELETE((const Derived*)this); |
| 269 } |
| 270 } |
| 265 void deref() const { this->unref(); } // Chrome prefers to call deref(). | 271 void deref() const { this->unref(); } // Chrome prefers to call deref(). |
| 266 int32_t getRefCnt() const { return fRefCnt; } // Used by Chrome unit tests. | 272 int32_t getRefCnt() const { return fRefCnt; } // Used by Chrome unit tests. |
| 267 | 273 |
| 274 protected: |
| 275 #ifdef SK_DEBUG |
| 276 ~SkNVRefCnt() { |
| 277 SkASSERTF(0 == fRefCnt, "NVRefCnt was %d", fRefCnt); |
| 278 } |
| 279 #endif |
| 280 |
| 268 private: | 281 private: |
| 269 mutable int32_t fRefCnt; | 282 mutable int32_t fRefCnt; |
| 270 }; | 283 }; |
| 271 | 284 |
| 272 #endif | 285 #endif |
| OLD | NEW |