| OLD | NEW |
| 1 // Copyright (c) 2010 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/base_api.h" |
| 10 #include "base/threading/thread_collision_warner.h" | 11 #include "base/threading/thread_collision_warner.h" |
| 11 | 12 |
| 12 namespace base { | 13 namespace base { |
| 13 | 14 |
| 14 namespace subtle { | 15 namespace subtle { |
| 15 | 16 |
| 16 class RefCountedBase { | 17 class BASE_API RefCountedBase { |
| 17 public: | 18 public: |
| 18 static bool ImplementsThreadSafeReferenceCounting() { return false; } | 19 static bool ImplementsThreadSafeReferenceCounting() { return false; } |
| 19 | 20 |
| 20 bool HasOneRef() const { return ref_count_ == 1; } | 21 bool HasOneRef() const { return ref_count_ == 1; } |
| 21 | 22 |
| 22 protected: | 23 protected: |
| 23 RefCountedBase(); | 24 RefCountedBase(); |
| 24 ~RefCountedBase(); | 25 ~RefCountedBase(); |
| 25 | 26 |
| 26 void AddRef() const; | 27 void AddRef() const; |
| 27 | 28 |
| 28 // Returns true if the object should self-delete. | 29 // Returns true if the object should self-delete. |
| 29 bool Release() const; | 30 bool Release() const; |
| 30 | 31 |
| 31 private: | 32 private: |
| 32 mutable int ref_count_; | 33 mutable int ref_count_; |
| 33 #ifndef NDEBUG | 34 #ifndef NDEBUG |
| 34 mutable bool in_dtor_; | 35 mutable bool in_dtor_; |
| 35 #endif | 36 #endif |
| 36 | 37 |
| 37 DFAKE_MUTEX(add_release_); | 38 DFAKE_MUTEX(add_release_); |
| 38 | 39 |
| 39 DISALLOW_COPY_AND_ASSIGN(RefCountedBase); | 40 DISALLOW_COPY_AND_ASSIGN(RefCountedBase); |
| 40 }; | 41 }; |
| 41 | 42 |
| 42 class RefCountedThreadSafeBase { | 43 class BASE_API RefCountedThreadSafeBase { |
| 43 public: | 44 public: |
| 44 static bool ImplementsThreadSafeReferenceCounting() { return true; } | 45 static bool ImplementsThreadSafeReferenceCounting() { return true; } |
| 45 | 46 |
| 46 bool HasOneRef() const; | 47 bool HasOneRef() const; |
| 47 | 48 |
| 48 protected: | 49 protected: |
| 49 RefCountedThreadSafeBase(); | 50 RefCountedThreadSafeBase(); |
| 50 ~RefCountedThreadSafeBase(); | 51 ~RefCountedThreadSafeBase(); |
| 51 | 52 |
| 52 void AddRef() const; | 53 void AddRef() const; |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 }; | 290 }; |
| 290 | 291 |
| 291 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without | 292 // Handy utility for creating a scoped_refptr<T> out of a T* explicitly without |
| 292 // having to retype all the template arguments | 293 // having to retype all the template arguments |
| 293 template <typename T> | 294 template <typename T> |
| 294 scoped_refptr<T> make_scoped_refptr(T* t) { | 295 scoped_refptr<T> make_scoped_refptr(T* t) { |
| 295 return scoped_refptr<T>(t); | 296 return scoped_refptr<T>(t); |
| 296 } | 297 } |
| 297 | 298 |
| 298 #endif // BASE_REF_COUNTED_H_ | 299 #endif // BASE_REF_COUNTED_H_ |
| OLD | NEW |