Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(178)

Side by Side Diff: include/core/SkRefCnt.h

Issue 19808007: Split atomic and mutex implementations and make inlinable. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Address dependency comments. Created 7 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « include/core/SkPostConfig.h ('k') | include/core/SkThread.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 #ifdef SK_DEBUG 82 #ifdef SK_DEBUG
83 void validate() const { 83 void validate() const {
84 SkASSERT(fRefCnt > 0); 84 SkASSERT(fRefCnt > 0);
85 } 85 }
86 #endif 86 #endif
87 87
(...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
280 typedef T* SkRefPtr::*unspecified_bool_type; 280 typedef T* SkRefPtr::*unspecified_bool_type;
281 operator unspecified_bool_type() const { 281 operator unspecified_bool_type() const {
282 return fObj ? &SkRefPtr::fObj : NULL; 282 return fObj ? &SkRefPtr::fObj : NULL;
283 } 283 }
284 284
285 private: 285 private:
286 T* fObj; 286 T* fObj;
287 }; 287 };
288 288
289 #endif 289 #endif
OLDNEW
« no previous file with comments | « include/core/SkPostConfig.h ('k') | include/core/SkThread.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698