| 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_
|
|
|