AK+Kernel: Remove RefPtrTraits template param in userspace code

Only the kernel actually uses RefPtrTraits, so let's not burden
userspace builds with the complexity.
This commit is contained in:
Andreas Kling 2022-05-07 12:50:54 +02:00
parent 9e994da2ac
commit 75dca629df
Notes: sideshowbarker 2024-07-17 10:14:15 +09:00
5 changed files with 30 additions and 29 deletions

View File

@ -115,11 +115,16 @@ class NonnullOwnPtrVector;
template<typename T> template<typename T>
class Optional; class Optional;
#ifdef KERNEL
template<typename T> template<typename T>
struct RefPtrTraits; struct RefPtrTraits;
template<typename T, typename PtrTraits = RefPtrTraits<T>> template<typename T, typename PtrTraits = RefPtrTraits<T>>
class RefPtr; class RefPtr;
#else
template<typename T>
class RefPtr;
#endif
template<typename T> template<typename T>
class OwnPtr; class OwnPtr;

View File

@ -17,10 +17,6 @@
namespace AK { namespace AK {
template<typename T, typename PtrTraits>
class RefPtr;
template<typename T>
class NonnullRefPtr;
template<typename T> template<typename T>
class WeakPtr; class WeakPtr;
@ -64,14 +60,14 @@ public:
template<typename U> template<typename U>
NonnullOwnPtr& operator=(NonnullOwnPtr<U> const&) = delete; NonnullOwnPtr& operator=(NonnullOwnPtr<U> const&) = delete;
template<typename U, typename PtrTraits = RefPtrTraits<U>> template<typename U>
NonnullOwnPtr(RefPtr<U, PtrTraits> const&) = delete; NonnullOwnPtr(RefPtr<U> const&) = delete;
template<typename U> template<typename U>
NonnullOwnPtr(NonnullRefPtr<U> const&) = delete; NonnullOwnPtr(NonnullRefPtr<U> const&) = delete;
template<typename U> template<typename U>
NonnullOwnPtr(WeakPtr<U> const&) = delete; NonnullOwnPtr(WeakPtr<U> const&) = delete;
template<typename U, typename PtrTraits = RefPtrTraits<U>> template<typename U>
NonnullOwnPtr& operator=(RefPtr<U, PtrTraits> const&) = delete; NonnullOwnPtr& operator=(RefPtr<U> const&) = delete;
template<typename U> template<typename U>
NonnullOwnPtr& operator=(NonnullRefPtr<U> const&) = delete; NonnullOwnPtr& operator=(NonnullRefPtr<U> const&) = delete;
template<typename U> template<typename U>

View File

@ -21,7 +21,7 @@ namespace AK {
template<typename T> template<typename T>
class OwnPtr; class OwnPtr;
template<typename T, typename PtrTraits> template<typename T>
class RefPtr; class RefPtr;
template<typename T> template<typename T>
@ -40,7 +40,7 @@ ALWAYS_INLINE void unref_if_not_null(T* ptr)
template<typename T> template<typename T>
class [[nodiscard]] NonnullRefPtr { class [[nodiscard]] NonnullRefPtr {
template<typename U, typename P> template<typename U>
friend class RefPtr; friend class RefPtr;
template<typename U> template<typename U>
friend class NonnullRefPtr; friend class NonnullRefPtr;

View File

@ -26,9 +26,9 @@ namespace AK {
template<typename T> template<typename T>
class OwnPtr; class OwnPtr;
template<typename T, typename PtrTraits> template<typename T>
class [[nodiscard]] RefPtr { class [[nodiscard]] RefPtr {
template<typename U, typename P> template<typename U>
friend class RefPtr; friend class RefPtr;
template<typename U> template<typename U>
friend class WeakPtr; friend class WeakPtr;
@ -80,8 +80,8 @@ public:
{ {
} }
template<typename U, typename P = RefPtrTraits<U>> template<typename U>
RefPtr(RefPtr<U, P>&& other) requires(IsConvertible<U*, T*>) RefPtr(RefPtr<U>&& other) requires(IsConvertible<U*, T*>)
: m_ptr(static_cast<T*>(other.leak_ref())) : m_ptr(static_cast<T*>(other.leak_ref()))
{ {
} }
@ -92,8 +92,8 @@ public:
ref_if_not_null(m_ptr); ref_if_not_null(m_ptr);
} }
template<typename U, typename P = RefPtrTraits<U>> template<typename U>
RefPtr(RefPtr<U, P> const& other) requires(IsConvertible<U*, T*>) RefPtr(RefPtr<U> const& other) requires(IsConvertible<U*, T*>)
: m_ptr(const_cast<T*>(static_cast<T const*>(other.ptr()))) : m_ptr(const_cast<T*>(static_cast<T const*>(other.ptr())))
{ {
ref_if_not_null(m_ptr); ref_if_not_null(m_ptr);
@ -117,8 +117,8 @@ public:
AK::swap(m_ptr, other.m_ptr); AK::swap(m_ptr, other.m_ptr);
} }
template<typename U, typename P = RefPtrTraits<U>> template<typename U>
void swap(RefPtr<U, P>& other) requires(IsConvertible<U*, T*>) void swap(RefPtr<U>& other) requires(IsConvertible<U*, T*>)
{ {
AK::swap(m_ptr, other.m_ptr); AK::swap(m_ptr, other.m_ptr);
} }
@ -130,8 +130,8 @@ public:
return *this; return *this;
} }
template<typename U, typename P = RefPtrTraits<U>> template<typename U>
ALWAYS_INLINE RefPtr& operator=(RefPtr<U, P>&& other) requires(IsConvertible<U*, T*>) ALWAYS_INLINE RefPtr& operator=(RefPtr<U>&& other) requires(IsConvertible<U*, T*>)
{ {
RefPtr tmp { move(other) }; RefPtr tmp { move(other) };
swap(tmp); swap(tmp);
@ -204,8 +204,8 @@ public:
return true; return true;
} }
template<typename U, typename P = RefPtrTraits<U>> template<typename U>
ALWAYS_INLINE bool assign_if_null(RefPtr<U, P>&& other) ALWAYS_INLINE bool assign_if_null(RefPtr<U>&& other)
{ {
if (this == &other) if (this == &other)
return is_null(); return is_null();
@ -315,14 +315,14 @@ inline NonnullRefPtr<T> static_ptr_cast(NonnullRefPtr<U> const& ptr)
return NonnullRefPtr<T>(static_cast<const T&>(*ptr)); return NonnullRefPtr<T>(static_cast<const T&>(*ptr));
} }
template<typename T, typename U, typename PtrTraits = RefPtrTraits<T>> template<typename T, typename U>
inline RefPtr<T> static_ptr_cast(RefPtr<U> const& ptr) inline RefPtr<T> static_ptr_cast(RefPtr<U> const& ptr)
{ {
return RefPtr<T, PtrTraits>(static_cast<const T*>(ptr.ptr())); return RefPtr<T>(static_cast<const T*>(ptr.ptr()));
} }
template<typename T, typename PtrTraitsT, typename U, typename PtrTraitsU> template<typename T, typename U>
inline void swap(RefPtr<T, PtrTraitsT>& a, RefPtr<U, PtrTraitsU>& b) requires(IsConvertible<U*, T*>) inline void swap(RefPtr<T>& a, RefPtr<U>& b) requires(IsConvertible<U*, T*>)
{ {
a.swap(b); a.swap(b);
} }

View File

@ -30,11 +30,11 @@ class WeakLink : public RefCounted<WeakLink> {
friend class WeakPtr; friend class WeakPtr;
public: public:
template<typename T, typename PtrTraits = RefPtrTraits<T>> template<typename T>
RefPtr<T, PtrTraits> strong_ref() const RefPtr<T> strong_ref() const
requires(IsBaseOf<RefCountedBase, T>) requires(IsBaseOf<RefCountedBase, T>)
{ {
RefPtr<T, PtrTraits> ref; RefPtr<T> ref;
{ {
if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) { if (!(m_consumers.fetch_add(1u << 1, AK::MemoryOrder::memory_order_acquire) & 1u)) {