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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 | 44 |
45 /** Return the reference count. Use only for debugging. */ | 45 /** Return the reference count. Use only for debugging. */ |
46 int32_t getRefCnt() const { return fRefCnt; } | 46 int32_t getRefCnt() const { return fRefCnt; } |
47 | 47 |
48 /** May return true if the caller is the only owner. | 48 /** May return true if the caller is the only owner. |
49 * Ensures that all previous owner's actions are complete. | 49 * Ensures that all previous owner's actions are complete. |
50 */ | 50 */ |
51 bool unique() const { | 51 bool unique() const { |
52 // We believe we're reading fRefCnt in a safe way here, so we stifle the
TSAN warning about | 52 // We believe we're reading fRefCnt in a safe way here, so we stifle the
TSAN warning about |
53 // an unproctected read. Generally, don't read fRefCnt, and don't stifl
e this warning. | 53 // an unproctected read. Generally, don't read fRefCnt, and don't stifl
e this warning. |
54 bool const unique = (1 == SK_ANNOTATE_UNPROTECTED_READ(fRefCnt)); | 54 bool const unique = (1 == sk_acquire_load(&fRefCnt)); |
55 if (unique) { | 55 if (unique) { |
56 // Acquire barrier (L/SL), if not provided by load of fRefCnt. | 56 // Acquire barrier (L/SL), if not provided by load of fRefCnt. |
57 // Prevents user's 'unique' code from happening before decrements. | 57 // Prevents user's 'unique' code from happening before decrements. |
58 //TODO: issue the barrier. | 58 //TODO: issue the barrier only when unique is true |
59 } | 59 } |
60 return unique; | 60 return unique; |
61 } | 61 } |
62 | 62 |
63 /** Increment the reference count. Must be balanced by a call to unref(). | 63 /** Increment the reference count. Must be balanced by a call to unref(). |
64 */ | 64 */ |
65 void ref() const { | 65 void ref() const { |
66 SkASSERT(fRefCnt > 0); | 66 SkASSERT(fRefCnt > 0); |
67 sk_atomic_inc(&fRefCnt); // No barrier required. | 67 sk_atomic_inc(&fRefCnt); // No barrier required. |
68 } | 68 } |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
241 }; | 241 }; |
242 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( | 242 // Can't use the #define trick below to guard a bare SkAutoTUnref(...) because i
t's templated. :( |
243 | 243 |
244 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { | 244 class SkAutoUnref : public SkAutoTUnref<SkRefCnt> { |
245 public: | 245 public: |
246 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} | 246 SkAutoUnref(SkRefCnt* obj) : SkAutoTUnref<SkRefCnt>(obj) {} |
247 }; | 247 }; |
248 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) | 248 #define SkAutoUnref(...) SK_REQUIRE_LOCAL_VAR(SkAutoUnref) |
249 | 249 |
250 #endif | 250 #endif |
OLD | NEW |