| 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 |
| 11 #define SkRefCnt_DEFINED | 11 #define SkRefCnt_DEFINED |
| 12 | 12 |
| 13 #include "SkDynamicAnnotations.h" | 13 #include "SkDynamicAnnotations.h" |
| 14 #include "SkThread.h" | 14 #include "SkThread.h" |
| 15 #include "SkInstCnt.h" | 15 #include "SkInstCnt.h" |
| 16 #include "SkTemplates.h" | 16 #include "SkTemplates.h" |
| 17 | 17 |
| 18 /** \class SkRefCntBase | 18 /** \class SkRefCntBase |
| 19 | 19 |
| 20 SkRefCntBase is the base class for objects that may be shared by multiple | 20 SkRefCntBase is the base class for objects that may be shared by multiple |
| 21 objects. When an existing owner wants to share a reference, it calls ref(). | 21 objects. When an existing owner wants to share a reference, it calls ref(). |
| 22 When an owner wants to release its reference, it calls unref(). When the | 22 When an owner wants to release its reference, it calls unref(). When the |
| 23 shared object's reference count goes to zero as the result of an unref() | 23 shared object's reference count goes to zero as the result of an unref() |
| 24 call, its (virtual) destructor is called. It is an error for the | 24 call, its (virtual) destructor is called. It is an error for the |
| 25 destructor to be called explicitly (or via the object going out of scope on | 25 destructor to be called explicitly (or via the object going out of scope on |
| 26 the stack or calling delete) if getRefCnt() > 1. | 26 the stack or calling delete) if getRefCnt() > 1. |
| 27 */ | 27 */ |
| 28 class SK_API SkRefCntBase : SkNoncopyable { | 28 class SK_API SkRefCntBase : SkNoncopyable { |
| 29 public: | 29 public: |
| 30 SK_DECLARE_INST_COUNT_ROOT(SkRefCntBase) | 30 SK_DECLARE_INST_COUNT(SkRefCntBase) |
| 31 | 31 |
| 32 /** Default construct, initializing the reference count to 1. | 32 /** Default construct, initializing the reference count to 1. |
| 33 */ | 33 */ |
| 34 SkRefCntBase() : fRefCnt(1) {} | 34 SkRefCntBase() : fRefCnt(1) {} |
| 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); |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 SkDELETE((const Derived*)this); | 272 SkDELETE((const Derived*)this); |
| 273 } | 273 } |
| 274 } | 274 } |
| 275 void deref() const { this->unref(); } // Chrome prefers to call deref(). | 275 void deref() const { this->unref(); } // Chrome prefers to call deref(). |
| 276 | 276 |
| 277 private: | 277 private: |
| 278 mutable int32_t fRefCnt; | 278 mutable int32_t fRefCnt; |
| 279 }; | 279 }; |
| 280 | 280 |
| 281 #endif | 281 #endif |
| OLD | NEW |