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 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 // prevents code conditioned on the result of unique() from running | 50 // prevents code conditioned on the result of unique() from running |
51 // until previous owners are all totally done calling unref(). | 51 // until previous owners are all totally done calling unref(). |
52 return true; | 52 return true; |
53 } | 53 } |
54 return false; | 54 return false; |
55 } | 55 } |
56 | 56 |
57 /** Increment the reference count. Must be balanced by a call to unref(). | 57 /** Increment the reference count. Must be balanced by a call to unref(). |
58 */ | 58 */ |
59 void ref() const { | 59 void ref() const { |
| 60 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
| 61 // Android employs some special subclasses that enable the fRefCnt to |
| 62 // go to zero, but not below, prior to reusing the object. This breaks |
| 63 // the use of unique() on such objects and as such should be removed |
| 64 // once the Android code is fixed. |
| 65 SkASSERT(fRefCnt >= 0); |
| 66 #else |
60 SkASSERT(fRefCnt > 0); | 67 SkASSERT(fRefCnt > 0); |
| 68 #endif |
61 (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_order_relaxed); // No
barrier required. | 69 (void)sk_atomic_fetch_add(&fRefCnt, +1, sk_memory_order_relaxed); // No
barrier required. |
62 } | 70 } |
63 | 71 |
64 /** Decrement the reference count. If the reference count is 1 before the | 72 /** Decrement the reference count. If the reference count is 1 before the |
65 decrement, then delete the object. Note that if this is the case, then | 73 decrement, then delete the object. Note that if this is the case, then |
66 the object needs to have been allocated via new, and not on the stack. | 74 the object needs to have been allocated via new, and not on the stack. |
67 */ | 75 */ |
68 void unref() const { | 76 void unref() const { |
69 SkASSERT(fRefCnt > 0); | 77 SkASSERT(fRefCnt > 0); |
70 // A release here acts in place of all releases we "should" have been do
ing in ref(). | 78 // A release here acts in place of all releases we "should" have been do
ing in ref(). |
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 SkDELETE((const Derived*)this); | 246 SkDELETE((const Derived*)this); |
239 } | 247 } |
240 } | 248 } |
241 void deref() const { this->unref(); } | 249 void deref() const { this->unref(); } |
242 | 250 |
243 private: | 251 private: |
244 mutable int32_t fRefCnt; | 252 mutable int32_t fRefCnt; |
245 }; | 253 }; |
246 | 254 |
247 #endif | 255 #endif |
OLD | NEW |