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

Unified Diff: webrtc/rtc_base/refcountedobject.h

Issue 3010883002: Implement concrete class RefCountedBase.
Patch Set: Use "= default" for destructors. Created 3 years, 4 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webrtc/rtc_base/refcountedobject.h
diff --git a/webrtc/rtc_base/refcountedobject.h b/webrtc/rtc_base/refcountedobject.h
index bf66af27a9b446edb24de8950d7347ed64a18b15..56333429465277c5496b0b61fb2cd03a9cc5ce0b 100644
--- a/webrtc/rtc_base/refcountedobject.h
+++ b/webrtc/rtc_base/refcountedobject.h
@@ -16,23 +16,12 @@
namespace rtc {
-template <class T>
-class RefCountedObject : public T {
+// Concrete base class with inline and non-virtual AddRef and Release.
+class RefCountedBase {
public:
- RefCountedObject() {}
-
- template <class P0>
- explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)) {}
+ int AddRef() const { return AtomicOps::Increment(&ref_count_); }
- template <class P0, class P1, class... Args>
- RefCountedObject(P0&& p0, P1&& p1, Args&&... args)
- : T(std::forward<P0>(p0),
- std::forward<P1>(p1),
- std::forward<Args>(args)...) {}
-
- virtual int AddRef() const { return AtomicOps::Increment(&ref_count_); }
-
- virtual int Release() const {
+ int Release() const {
int count = AtomicOps::Decrement(&ref_count_);
if (!count) {
delete this;
@@ -46,16 +35,38 @@ class RefCountedObject : public T {
// performs the test for a reference count of one, and performs the memory
// barrier needed for the owning thread to act on the object, knowing that it
// has exclusive access to the object.
- virtual bool HasOneRef() const {
+ bool HasOneRef() const {
return AtomicOps::AcquireLoad(&ref_count_) == 1;
}
protected:
- virtual ~RefCountedObject() {}
+ virtual ~RefCountedBase() = default;
mutable volatile int ref_count_ = 0;
};
+template <class T>
+class RefCountedObject : public T, protected virtual RefCountedBase {
+ public:
+ RefCountedObject() {}
+
+ template <class P0>
+ explicit RefCountedObject(P0&& p0) : T(std::forward<P0>(p0)) {}
+
+ template <class P0, class P1, class... Args>
+ RefCountedObject(P0&& p0, P1&& p1, Args&&... args)
+ : T(std::forward<P0>(p0),
+ std::forward<P1>(p1),
+ std::forward<Args>(args)...) {}
+
+ virtual int AddRef() const { return RefCountedBase::AddRef(); }
+ virtual int Release() const { return RefCountedBase::Release(); }
+ virtual bool HasOneRef() const { return RefCountedBase::HasOneRef(); }
+
+ protected:
+ virtual ~RefCountedObject() = default;
+};
+
} // namespace rtc
#endif // WEBRTC_RTC_BASE_REFCOUNTEDOBJECT_H_
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698