OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef BASE_REF_COUNTED_H_ | 5 #ifndef BASE_REF_COUNTED_H_ |
6 #define BASE_REF_COUNTED_H_ | 6 #define BASE_REF_COUNTED_H_ |
7 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "base/atomic_ref_count.h" | 9 #include "base/atomic_ref_count.h" |
10 #include "base/thread_collision_warner.h" | 10 #include "base/thread_collision_warner.h" |
11 | 11 |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 template <class T, typename Traits> class RefCountedThreadSafe; | 103 template <class T, typename Traits> class RefCountedThreadSafe; |
104 | 104 |
105 // Default traits for RefCountedThreadSafe<T>. Deletes the object when its ref | 105 // Default traits for RefCountedThreadSafe<T>. Deletes the object when its ref |
106 // count reaches 0. Overload to delete it on a different thread etc. | 106 // count reaches 0. Overload to delete it on a different thread etc. |
107 template<typename T> | 107 template<typename T> |
108 struct DefaultRefCountedThreadSafeTraits { | 108 struct DefaultRefCountedThreadSafeTraits { |
109 static void Destruct(T* x) { | 109 static void Destruct(T* x) { |
110 // Delete through RefCountedThreadSafe to make child classes only need to be | 110 // Delete through RefCountedThreadSafe to make child classes only need to be |
111 // friend with RefCountedThreadSafe instead of this struct, which is an | 111 // friend with RefCountedThreadSafe instead of this struct, which is an |
112 // implementation detail. | 112 // implementation detail. |
113 RefCountedThreadSafe<T, DefaultRefCountedThreadSafeTraits>::DeleteInternal(x
); | 113 RefCountedThreadSafe<T, |
| 114 DefaultRefCountedThreadSafeTraits>::DeleteInternal(x); |
114 } | 115 } |
115 }; | 116 }; |
116 | 117 |
117 // | 118 // |
118 // A thread-safe variant of RefCounted<T> | 119 // A thread-safe variant of RefCounted<T> |
119 // | 120 // |
120 // class MyFoo : public base::RefCountedThreadSafe<MyFoo> { | 121 // class MyFoo : public base::RefCountedThreadSafe<MyFoo> { |
121 // ... | 122 // ... |
122 // }; | 123 // }; |
123 // | 124 // |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 }; | 289 }; |
289 | 290 |
290 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 291 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
291 // having to retype all the template arguments | 292 // having to retype all the template arguments |
292 template <typename T> | 293 template <typename T> |
293 scoped_refptr<T> make_scoped_refptr(T* t) { | 294 scoped_refptr<T> make_scoped_refptr(T* t) { |
294 return scoped_refptr<T>(t); | 295 return scoped_refptr<T>(t); |
295 } | 296 } |
296 | 297 |
297 #endif // BASE_REF_COUNTED_H_ | 298 #endif // BASE_REF_COUNTED_H_ |
OLD | NEW |