diff options
author | Andreas Kling <kling@serenityos.org> | 2022-08-19 20:53:40 +0200 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-08-20 17:20:43 +0200 |
commit | 11eee67b8510767d76fb4793e3b62ac1793dd723 (patch) | |
tree | 8ce47a3813ce74bba56c60f62b29bdd6cdf287da /AK/RefPtr.h | |
parent | e475263113387404e63cdc3666391934604eb6e7 (diff) | |
download | serenity-11eee67b8510767d76fb4793e3b62ac1793dd723.zip |
Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:
- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable
This patch renames the Kernel classes so that they can coexist with
the original AK classes:
- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable
The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
Diffstat (limited to 'AK/RefPtr.h')
-rw-r--r-- | AK/RefPtr.h | 48 |
1 files changed, 21 insertions, 27 deletions
diff --git a/AK/RefPtr.h b/AK/RefPtr.h index 11e27a2c1c..9e06c900b9 100644 --- a/AK/RefPtr.h +++ b/AK/RefPtr.h @@ -8,18 +8,14 @@ #define REFPTR_SCRUB_BYTE 0xe0 -#ifdef KERNEL -# include <Kernel/Library/ThreadSafeRefPtr.h> -#else - -# include <AK/Assertions.h> -# include <AK/Atomic.h> -# include <AK/Error.h> -# include <AK/Format.h> -# include <AK/NonnullRefPtr.h> -# include <AK/StdLibExtras.h> -# include <AK/Traits.h> -# include <AK/Types.h> +#include <AK/Assertions.h> +#include <AK/Atomic.h> +#include <AK/Error.h> +#include <AK/Format.h> +#include <AK/NonnullRefPtr.h> +#include <AK/StdLibExtras.h> +#include <AK/Traits.h> +#include <AK/Types.h> namespace AK { @@ -104,9 +100,9 @@ public: ALWAYS_INLINE ~RefPtr() { clear(); -# ifdef SANITIZE_PTRS +#ifdef SANITIZE_PTRS m_ptr = reinterpret_cast<T*>(explode_byte(REFPTR_SCRUB_BYTE)); -# endif +#endif } template<typename U> @@ -236,14 +232,14 @@ public: } ALWAYS_INLINE T* ptr() { return as_ptr(); } - ALWAYS_INLINE const T* ptr() const { return as_ptr(); } + ALWAYS_INLINE T const* ptr() const { return as_ptr(); } ALWAYS_INLINE T* operator->() { return as_nonnull_ptr(); } - ALWAYS_INLINE const T* operator->() const + ALWAYS_INLINE T const* operator->() const { return as_nonnull_ptr(); } @@ -253,12 +249,12 @@ public: return *as_nonnull_ptr(); } - ALWAYS_INLINE const T& operator*() const + ALWAYS_INLINE T const& operator*() const { return *as_nonnull_ptr(); } - ALWAYS_INLINE operator const T*() const { return as_ptr(); } + ALWAYS_INLINE operator T const*() const { return as_ptr(); } ALWAYS_INLINE operator T*() { return as_ptr(); } ALWAYS_INLINE operator bool() { return !is_null(); } @@ -282,8 +278,8 @@ public: template<typename U> bool operator!=(NonnullRefPtr<U>& other) { return as_ptr() != other.m_ptr; } - bool operator==(const T* other) const { return as_ptr() == other; } - bool operator!=(const T* other) const { return as_ptr() != other; } + bool operator==(T const* other) const { return as_ptr() == other; } + bool operator!=(T const* other) const { return as_ptr() != other; } bool operator==(T* other) { return as_ptr() == other; } bool operator!=(T* other) { return as_ptr() != other; } @@ -306,17 +302,17 @@ private: }; template<typename T> -struct Formatter<RefPtr<T>> : Formatter<const T*> { +struct Formatter<RefPtr<T>> : Formatter<T const*> { ErrorOr<void> format(FormatBuilder& builder, RefPtr<T> const& value) { - return Formatter<const T*>::format(builder, value.ptr()); + return Formatter<T const*>::format(builder, value.ptr()); } }; template<typename T> struct Traits<RefPtr<T>> : public GenericTraits<RefPtr<T>> { using PeekType = T*; - using ConstPeekType = const T*; + using ConstPeekType = T const*; static unsigned hash(RefPtr<T> const& p) { return ptr_hash(p.ptr()); } static bool equals(RefPtr<T> const& a, RefPtr<T> const& b) { return a.ptr() == b.ptr(); } }; @@ -324,13 +320,13 @@ struct Traits<RefPtr<T>> : public GenericTraits<RefPtr<T>> { template<typename T, typename U> inline NonnullRefPtr<T> static_ptr_cast(NonnullRefPtr<U> const& ptr) { - return NonnullRefPtr<T>(static_cast<const T&>(*ptr)); + return NonnullRefPtr<T>(static_cast<T const&>(*ptr)); } template<typename T, typename U> inline RefPtr<T> static_ptr_cast(RefPtr<U> const& ptr) { - return RefPtr<T>(static_cast<const T*>(ptr.ptr())); + return RefPtr<T>(static_cast<T const*>(ptr.ptr())); } template<typename T, typename U> @@ -375,5 +371,3 @@ using AK::adopt_ref_if_nonnull; using AK::RefPtr; using AK::static_ptr_cast; using AK::try_make_ref_counted; - -#endif |