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

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: Include all the files. Created 7 years, 5 months 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
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 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
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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698