OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_MEMORY_REF_COUNTED_H_ | 5 #ifndef BASE_MEMORY_REF_COUNTED_H_ |
6 #define BASE_MEMORY_REF_COUNTED_H_ | 6 #define BASE_MEMORY_REF_COUNTED_H_ |
7 | 7 |
8 #include <cassert> | 8 #include <cassert> |
9 | 9 |
10 #include "base/atomic_ref_count.h" | 10 #include "base/atomic_ref_count.h" |
11 #include "base/base_export.h" | 11 #include "base/base_export.h" |
12 #include "base/threading/thread_collision_warner.h" | 12 #include "base/threading/thread_collision_warner.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 namespace subtle { | 16 namespace subtle { |
17 | 17 |
18 class BASE_EXPORT RefCountedBase { | 18 class BASE_EXPORT RefCountedBase { |
19 public: | 19 public: |
20 static bool ImplementsThreadSafeReferenceCounting() { return false; } | |
21 | |
22 bool HasOneRef() const { return ref_count_ == 1; } | 20 bool HasOneRef() const { return ref_count_ == 1; } |
23 | 21 |
24 protected: | 22 protected: |
25 RefCountedBase(); | 23 RefCountedBase(); |
26 ~RefCountedBase(); | 24 ~RefCountedBase(); |
27 | 25 |
28 void AddRef() const; | 26 void AddRef() const; |
29 | 27 |
30 // Returns true if the object should self-delete. | 28 // Returns true if the object should self-delete. |
31 bool Release() const; | 29 bool Release() const; |
32 | 30 |
33 private: | 31 private: |
34 mutable int ref_count_; | 32 mutable int ref_count_; |
35 #ifndef NDEBUG | 33 #ifndef NDEBUG |
36 mutable bool in_dtor_; | 34 mutable bool in_dtor_; |
37 #endif | 35 #endif |
38 | 36 |
39 DFAKE_MUTEX(add_release_); | 37 DFAKE_MUTEX(add_release_); |
40 | 38 |
41 DISALLOW_COPY_AND_ASSIGN(RefCountedBase); | 39 DISALLOW_COPY_AND_ASSIGN(RefCountedBase); |
42 }; | 40 }; |
43 | 41 |
44 class BASE_EXPORT RefCountedThreadSafeBase { | 42 class BASE_EXPORT RefCountedThreadSafeBase { |
45 public: | 43 public: |
46 static bool ImplementsThreadSafeReferenceCounting() { return true; } | |
47 | |
48 bool HasOneRef() const; | 44 bool HasOneRef() const; |
49 | 45 |
50 protected: | 46 protected: |
51 RefCountedThreadSafeBase(); | 47 RefCountedThreadSafeBase(); |
52 ~RefCountedThreadSafeBase(); | 48 ~RefCountedThreadSafeBase(); |
53 | 49 |
54 void AddRef() const; | 50 void AddRef() const; |
55 | 51 |
56 // Returns true if the object should self-delete. | 52 // Returns true if the object should self-delete. |
57 bool Release() const; | 53 bool Release() const; |
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 }; | 301 }; |
306 | 302 |
307 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 303 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
308 // having to retype all the template arguments | 304 // having to retype all the template arguments |
309 template <typename T> | 305 template <typename T> |
310 scoped_refptr<T> make_scoped_refptr(T* t) { | 306 scoped_refptr<T> make_scoped_refptr(T* t) { |
311 return scoped_refptr<T>(t); | 307 return scoped_refptr<T>(t); |
312 } | 308 } |
313 | 309 |
314 #endif // BASE_MEMORY_REF_COUNTED_H_ | 310 #endif // BASE_MEMORY_REF_COUNTED_H_ |
OLD | NEW |