| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 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 SkWeakRefCnt_DEFINED | 8 #ifndef SkWeakRefCnt_DEFINED |
| 9 #define SkWeakRefCnt_DEFINED | 9 #define SkWeakRefCnt_DEFINED |
| 10 | 10 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 if (myRef.try_ref()) { | 44 if (myRef.try_ref()) { |
| 45 ... // use myRef | 45 ... // use myRef |
| 46 myRef.unref(); | 46 myRef.unref(); |
| 47 } else { | 47 } else { |
| 48 // myRef is in the disposed state | 48 // myRef is in the disposed state |
| 49 } | 49 } |
| 50 myRef.weak_unref(); | 50 myRef.weak_unref(); |
| 51 */ | 51 */ |
| 52 class SK_API SkWeakRefCnt : public SkRefCnt { | 52 class SK_API SkWeakRefCnt : public SkRefCnt { |
| 53 public: | 53 public: |
| 54 SK_DECLARE_INST_COUNT(SkWeakRefCnt) | |
| 55 | |
| 56 /** Default construct, initializing the reference counts to 1. | 54 /** Default construct, initializing the reference counts to 1. |
| 57 The strong references collectively hold one weak reference. When the | 55 The strong references collectively hold one weak reference. When the |
| 58 strong reference count goes to zero, the collectively held weak | 56 strong reference count goes to zero, the collectively held weak |
| 59 reference is released. | 57 reference is released. |
| 60 */ | 58 */ |
| 61 SkWeakRefCnt() : SkRefCnt(), fWeakCnt(1) {} | 59 SkWeakRefCnt() : SkRefCnt(), fWeakCnt(1) {} |
| 62 | 60 |
| 63 /** Destruct, asserting that the weak reference count is 1. | 61 /** Destruct, asserting that the weak reference count is 1. |
| 64 */ | 62 */ |
| 65 virtual ~SkWeakRefCnt() { | 63 virtual ~SkWeakRefCnt() { |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 weak_unref(); | 150 weak_unref(); |
| 153 } | 151 } |
| 154 | 152 |
| 155 /* Invariant: fWeakCnt = #weak + (fRefCnt > 0 ? 1 : 0) */ | 153 /* Invariant: fWeakCnt = #weak + (fRefCnt > 0 ? 1 : 0) */ |
| 156 mutable int32_t fWeakCnt; | 154 mutable int32_t fWeakCnt; |
| 157 | 155 |
| 158 typedef SkRefCnt INHERITED; | 156 typedef SkRefCnt INHERITED; |
| 159 }; | 157 }; |
| 160 | 158 |
| 161 #endif | 159 #endif |
| OLD | NEW |