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 "SkAtomics.h" | 13 #include "SkAtomics.h" |
14 #include "SkInstCnt.h" | |
15 #include "SkTemplates.h" | 14 #include "SkTemplates.h" |
16 | 15 |
17 /** \class SkRefCntBase | 16 /** \class SkRefCntBase |
18 | 17 |
19 SkRefCntBase is the base class for objects that may be shared by multiple | 18 SkRefCntBase is the base class for objects that may be shared by multiple |
20 objects. When an existing owner wants to share a reference, it calls ref(). | 19 objects. When an existing owner wants to share a reference, it calls ref(). |
21 When an owner wants to release its reference, it calls unref(). When the | 20 When an owner wants to release its reference, it calls unref(). When the |
22 shared object's reference count goes to zero as the result of an unref() | 21 shared object's reference count goes to zero as the result of an unref() |
23 call, its (virtual) destructor is called. It is an error for the | 22 call, its (virtual) destructor is called. It is an error for the |
24 destructor to be called explicitly (or via the object going out of scope on | 23 destructor to be called explicitly (or via the object going out of scope on |
25 the stack or calling delete) if getRefCnt() > 1. | 24 the stack or calling delete) if getRefCnt() > 1. |
26 */ | 25 */ |
27 class SK_API SkRefCntBase : SkNoncopyable { | 26 class SK_API SkRefCntBase : SkNoncopyable { |
28 public: | 27 public: |
29 SK_DECLARE_INST_COUNT(SkRefCntBase) | |
30 | |
31 /** Default construct, initializing the reference count to 1. | 28 /** Default construct, initializing the reference count to 1. |
32 */ | 29 */ |
33 SkRefCntBase() : fRefCnt(1) {} | 30 SkRefCntBase() : fRefCnt(1) {} |
34 | 31 |
35 /** Destruct, asserting that the reference count is 1. | 32 /** Destruct, asserting that the reference count is 1. |
36 */ | 33 */ |
37 virtual ~SkRefCntBase() { | 34 virtual ~SkRefCntBase() { |
38 #ifdef SK_DEBUG | 35 #ifdef SK_DEBUG |
39 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); | 36 SkASSERTF(fRefCnt == 1, "fRefCnt was %d", fRefCnt); |
40 fRefCnt = 0; // illegal value, to catch us if we reuse after delete | 37 fRefCnt = 0; // illegal value, to catch us if we reuse after delete |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 SkDELETE((const Derived*)this); | 240 SkDELETE((const Derived*)this); |
244 } | 241 } |
245 } | 242 } |
246 void deref() const { this->unref(); } | 243 void deref() const { this->unref(); } |
247 | 244 |
248 private: | 245 private: |
249 mutable int32_t fRefCnt; | 246 mutable int32_t fRefCnt; |
250 }; | 247 }; |
251 | 248 |
252 #endif | 249 #endif |
OLD | NEW |