OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 // Provides a base class for reference-counted classes. | 5 // Provides a base class for reference-counted classes. |
6 | 6 |
7 #ifndef MOJO_EDK_SYSTEM_REF_COUNTED_H_ | 7 #ifndef MOJO_EDK_SYSTEM_REF_COUNTED_H_ |
8 #define MOJO_EDK_SYSTEM_REF_COUNTED_H_ | 8 #define MOJO_EDK_SYSTEM_REF_COUNTED_H_ |
9 | 9 |
10 #include <assert.h> | 10 #include <assert.h> |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
68 public: | 68 public: |
69 void Release() const { | 69 void Release() const { |
70 if (internal::RefCountedThreadSafeBase::Release()) | 70 if (internal::RefCountedThreadSafeBase::Release()) |
71 delete static_cast<const T*>(this); | 71 delete static_cast<const T*>(this); |
72 } | 72 } |
73 | 73 |
74 protected: | 74 protected: |
75 RefCountedThreadSafe() {} | 75 RefCountedThreadSafe() {} |
76 ~RefCountedThreadSafe() {} | 76 ~RefCountedThreadSafe() {} |
77 | 77 |
| 78 private: |
78 #ifndef NDEBUG | 79 #ifndef NDEBUG |
79 template <typename U> | 80 template <typename U> |
80 friend RefPtr<U> AdoptRef(U*); | 81 friend RefPtr<U> AdoptRef(U*); |
81 void Adopt() { internal::RefCountedThreadSafeBase::Adopt(); } | 82 void Adopt() { internal::RefCountedThreadSafeBase::Adopt(); } |
82 #endif | 83 #endif |
83 | 84 |
84 private: | |
85 MOJO_DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe); | 85 MOJO_DISALLOW_COPY_AND_ASSIGN(RefCountedThreadSafe); |
86 }; | 86 }; |
87 | 87 |
88 // If you subclass |RefCountedThreadSafe| and want to keep your destructor | 88 // If you subclass |RefCountedThreadSafe| and want to keep your destructor |
89 // private, use this. (See the example above |RefCountedThreadSafe|.) | 89 // private, use this. (See the example above |RefCountedThreadSafe|.) |
90 #define FRIEND_REF_COUNTED_THREAD_SAFE(T) \ | 90 #define FRIEND_REF_COUNTED_THREAD_SAFE(T) \ |
91 friend class ::mojo::system::RefCountedThreadSafe<T> | 91 friend class ::mojo::system::RefCountedThreadSafe<T> |
92 | 92 |
93 // If you want to keep your constructor(s) private and still want to use | 93 // If you want to keep your constructor(s) private and still want to use |
94 // |MakeRefCounted<T>()|, use this. (See the example above | 94 // |MakeRefCounted<T>()|, use this. (See the example above |
95 // |RefCountedThreadSafe|.) | 95 // |RefCountedThreadSafe|.) |
96 #define FRIEND_MAKE_REF_COUNTED(T) \ | 96 #define FRIEND_MAKE_REF_COUNTED(T) \ |
97 friend class ::mojo::system::internal::MakeRefCountedHelper<T> | 97 friend class ::mojo::system::internal::MakeRefCountedHelper<T> |
98 | 98 |
99 } // namespace system | 99 } // namespace system |
100 } // namespace mojo | 100 } // namespace mojo |
101 | 101 |
102 #endif // MOJO_EDK_SYSTEM_REF_COUNTED_H_ | 102 #endif // MOJO_EDK_SYSTEM_REF_COUNTED_H_ |
OLD | NEW |