| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 | 43 |
| 44 /** Return the reference count. Use only for debugging. */ | 44 /** Return the reference count. Use only for debugging. */ |
| 45 int32_t getRefCnt() const { return fRefCnt; } | 45 int32_t getRefCnt() const { return fRefCnt; } |
| 46 | 46 |
| 47 /** Returns true if the caller is the only owner. | 47 /** Returns true if the caller is the only owner. |
| 48 * Ensures that all previous owner's actions are complete. | 48 * Ensures that all previous owner's actions are complete. |
| 49 */ | 49 */ |
| 50 bool unique() const { | 50 bool unique() const { |
| 51 bool const unique = (1 == fRefCnt); | 51 bool const unique = (1 == fRefCnt); |
| 52 if (unique) { | 52 if (unique) { |
| 53 // Aquire barrier (L/SL), if not provided by load of fRefCnt. | 53 // Acquire barrier (L/SL), if not provided by load of fRefCnt. |
| 54 // Prevents user's 'unique' code from happening before decrements. | 54 // Prevents user's 'unique' code from happening before decrements. |
| 55 //TODO: issue the barrier. | 55 //TODO: issue the barrier. |
| 56 } | 56 } |
| 57 return unique; | 57 return unique; |
| 58 } | 58 } |
| 59 | 59 |
| 60 /** Increment the reference count. Must be balanced by a call to unref(). | 60 /** Increment the reference count. Must be balanced by a call to unref(). |
| 61 */ | 61 */ |
| 62 void ref() const { | 62 void ref() const { |
| 63 SkASSERT(fRefCnt > 0); | 63 SkASSERT(fRefCnt > 0); |
| 64 sk_atomic_inc(&fRefCnt); // No barrier required. | 64 sk_atomic_inc(&fRefCnt); // No barrier required. |
| 65 } | 65 } |
| 66 | 66 |
| 67 /** Decrement the reference count. If the reference count is 1 before the | 67 /** Decrement the reference count. If the reference count is 1 before the |
| 68 decrement, then delete the object. Note that if this is the case, then | 68 decrement, then delete the object. Note that if this is the case, then |
| 69 the object needs to have been allocated via new, and not on the stack. | 69 the object needs to have been allocated via new, and not on the stack. |
| 70 */ | 70 */ |
| 71 void unref() const { | 71 void unref() const { |
| 72 SkASSERT(fRefCnt > 0); | 72 SkASSERT(fRefCnt > 0); |
| 73 // Release barrier (SL/S), if not provided below. | 73 // Release barrier (SL/S), if not provided below. |
| 74 if (sk_atomic_dec(&fRefCnt) == 1) { | 74 if (sk_atomic_dec(&fRefCnt) == 1) { |
| 75 // Aquire barrier (L/SL), if not provided above. | 75 // Acquire barrier (L/SL), if not provided above. |
| 76 // Prevents code in dispose from happening before the decrement. | 76 // Prevents code in dispose from happening before the decrement. |
| 77 sk_membar_aquire__after_atomic_dec(); | 77 sk_membar_acquire__after_atomic_dec(); |
| 78 internal_dispose(); | 78 internal_dispose(); |
| 79 } | 79 } |
| 80 } | 80 } |
| 81 | 81 |
| 82 void validate() const { | 82 void validate() const { |
| 83 SkASSERT(fRefCnt > 0); | 83 SkASSERT(fRefCnt > 0); |
| 84 } | 84 } |
| 85 | 85 |
| 86 /** | 86 /** |
| 87 * Alias for unref(), for compatibility with WTF::RefPtr. | 87 * Alias for unref(), for compatibility with WTF::RefPtr. |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 265 typedef T* SkRefPtr::*unspecified_bool_type; | 265 typedef T* SkRefPtr::*unspecified_bool_type; |
| 266 operator unspecified_bool_type() const { | 266 operator unspecified_bool_type() const { |
| 267 return fObj ? &SkRefPtr::fObj : NULL; | 267 return fObj ? &SkRefPtr::fObj : NULL; |
| 268 } | 268 } |
| 269 | 269 |
| 270 private: | 270 private: |
| 271 T* fObj; | 271 T* fObj; |
| 272 }; | 272 }; |
| 273 | 273 |
| 274 #endif | 274 #endif |
| OLD | NEW |