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>
class Optional;
#ifdef KERNEL
template<typename T>
struct RefPtrTraits;
template<typename T, typename PtrTraits = RefPtrTraits<T>>
class RefPtr;
#else
template<typename T>
class RefPtr;
#endif
template<typename T>
class OwnPtr;

View file

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

View file

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

View file

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

View file

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