From eba683130070bc202058580b657393f937ca8a8c Mon Sep 17 00:00:00 2001 From: Danil Chapovalov Date: Tue, 22 Oct 2024 16:26:05 +0200 Subject: [PATCH] Alias instead of reimplement rtc::RefCountedObject Mentioned reasons for re-implementing it do not apply when simplest form of aliasing is used. Bug: webrtc:42225969 Change-Id: If8b51f173faf4c66cde74413f4fbc7c72ad87323 Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/366460 Auto-Submit: Danil Chapovalov Reviewed-by: Harald Alvestrand Commit-Queue: Harald Alvestrand Cr-Commit-Position: refs/heads/main@{#43285} --- rtc_base/ref_counted_object.h | 50 ++--------------------------------- 1 file changed, 2 insertions(+), 48 deletions(-) diff --git a/rtc_base/ref_counted_object.h b/rtc_base/ref_counted_object.h index 007e9f942b..4e72217660 100644 --- a/rtc_base/ref_counted_object.h +++ b/rtc_base/ref_counted_object.h @@ -89,54 +89,8 @@ class FinalRefCountedObject final : public T { // Backwards compatibe aliases. // TODO: https://issues.webrtc.org/42225969 - deprecate and remove. namespace rtc { -// Because there are users of this template that use "friend -// rtc::RefCountedObject<>" to give access to a private destructor, some -// indirection is needed; "friend" declarations cannot span an "using" -// declaration. Since a templated class on top of a templated class can't access -// the subclass' protected members, we duplicate the entire class instead. -template -class RefCountedObject : public T { - public: - RefCountedObject() {} - - RefCountedObject(const RefCountedObject&) = delete; - RefCountedObject& operator=(const RefCountedObject&) = delete; - - template - explicit RefCountedObject(P0&& p0) : T(std::forward(p0)) {} - - template - RefCountedObject(P0&& p0, P1&& p1, Args&&... args) - : T(std::forward(p0), - std::forward(p1), - std::forward(args)...) {} - - void AddRef() const override { ref_count_.IncRef(); } - - webrtc::RefCountReleaseStatus Release() const override { - const auto status = ref_count_.DecRef(); - if (status == webrtc::RefCountReleaseStatus::kDroppedLastRef) { - delete this; - } - return status; - } - - // Return whether the reference count is one. If the reference count is used - // in the conventional way, a reference count of 1 implies that the current - // thread owns the reference and no other thread shares it. This call - // 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 { return ref_count_.HasOneRef(); } - - protected: - ~RefCountedObject() override {} - - mutable webrtc::webrtc_impl::RefCounter ref_count_{0}; -}; - -template -using FinalRefCountedObject = webrtc::FinalRefCountedObject; +using ::webrtc::FinalRefCountedObject; +using ::webrtc::RefCountedObject; } // namespace rtc #endif // RTC_BASE_REF_COUNTED_OBJECT_H_