summaryrefslogtreecommitdiffhomepage
path: root/Kernel/NewKit
diff options
context:
space:
mode:
authorAmlal <amlal@zka.com>2024-07-21 09:48:52 +0200
committerAmlal <amlal@zka.com>2024-07-21 09:48:52 +0200
commitea937555b04ae7f39785341e45955b48515e5bf1 (patch)
tree9d865f6eeba5cc395e6cdaa5b1e6fdcf58361b0f /Kernel/NewKit
parent650fee520f526d9cd5ffa75735bd94d5140dd247 (diff)
[IMP] MHR-36: Much better ref class
Signed-off-by: Amlal <amlal@zka.com>
Diffstat (limited to 'Kernel/NewKit')
-rw-r--r--Kernel/NewKit/ErrorOr.hpp2
-rw-r--r--Kernel/NewKit/NewKit.hpp2
-rw-r--r--Kernel/NewKit/OwnPtr.hpp2
-rw-r--r--Kernel/NewKit/PageManager.hpp2
-rw-r--r--Kernel/NewKit/Pmm.hpp2
-rw-r--r--Kernel/NewKit/Ref.hxx (renamed from Kernel/NewKit/Ref.hpp)28
-rw-r--r--Kernel/NewKit/Stream.hpp2
7 files changed, 24 insertions, 16 deletions
diff --git a/Kernel/NewKit/ErrorOr.hpp b/Kernel/NewKit/ErrorOr.hpp
index a528de57..7e261abf 100644
--- a/Kernel/NewKit/ErrorOr.hpp
+++ b/Kernel/NewKit/ErrorOr.hpp
@@ -10,7 +10,7 @@
#pragma once
#include <NewKit/Defines.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
namespace Kernel
{
diff --git a/Kernel/NewKit/NewKit.hpp b/Kernel/NewKit/NewKit.hpp
index 761a0411..144a0ea9 100644
--- a/Kernel/NewKit/NewKit.hpp
+++ b/Kernel/NewKit/NewKit.hpp
@@ -16,7 +16,7 @@
#include <NewKit/MutableArray.hpp>
#include <NewKit/New.hpp>
#include <NewKit/OwnPtr.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
#include <NewKit/Stream.hpp>
#include <KernelKit/ProcessHeap.hxx>
#include <NewKit/Utils.hpp>
diff --git a/Kernel/NewKit/OwnPtr.hpp b/Kernel/NewKit/OwnPtr.hpp
index 7aa2a247..6157a1b6 100644
--- a/Kernel/NewKit/OwnPtr.hpp
+++ b/Kernel/NewKit/OwnPtr.hpp
@@ -9,7 +9,7 @@
#include <NewKit/Defines.hpp>
#include <NewKit/KernelCheck.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
namespace Kernel
{
diff --git a/Kernel/NewKit/PageManager.hpp b/Kernel/NewKit/PageManager.hpp
index 89c449f7..57b842ba 100644
--- a/Kernel/NewKit/PageManager.hpp
+++ b/Kernel/NewKit/PageManager.hpp
@@ -11,7 +11,7 @@
#include <NewKit/Defines.hpp>
#include <NewKit/PageAllocator.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
#ifndef kBadAddress
#define kBadAddress (0)
diff --git a/Kernel/NewKit/Pmm.hpp b/Kernel/NewKit/Pmm.hpp
index 8c918de4..46db1879 100644
--- a/Kernel/NewKit/Pmm.hpp
+++ b/Kernel/NewKit/Pmm.hpp
@@ -8,7 +8,7 @@
#pragma once
#include <NewKit/PageManager.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
namespace Kernel
{
diff --git a/Kernel/NewKit/Ref.hpp b/Kernel/NewKit/Ref.hxx
index 0b0f89cc..69150054 100644
--- a/Kernel/NewKit/Ref.hpp
+++ b/Kernel/NewKit/Ref.hxx
@@ -18,39 +18,47 @@ namespace Kernel
{
public:
Ref() = default;
- ~Ref() = default;
+
+ ~Ref()
+ {
+ if (fStrong)
+ {
+ fClass = nullptr;
+ }
+ }
public:
Ref(T cls, const bool& strong = false)
- : fClass(cls), fStrong(strong)
+ : fClass(&cls), fStrong(strong)
{
}
Ref& operator=(T ref)
{
- fClass = ref;
+ *fClass = ref;
return *this;
}
public:
T operator->() const
{
- return fClass;
+ return *fClass;
}
T& Leak() noexcept
{
- return fClass;
+ return *fClass;
}
- T& Fetch() const noexcept
+ T& TryLeak() const noexcept
{
- return fClass;
+ MUST_PASS(*fClass);
+ return *fClass;
}
T operator*()
{
- return fClass;
+ return *fClass;
}
bool IsStrong() const
@@ -64,8 +72,8 @@ namespace Kernel
}
private:
- T fClass;
- bool fStrong{false};
+ T* fClass;
+ Bool fStrong{false};
};
template <typename T>
diff --git a/Kernel/NewKit/Stream.hpp b/Kernel/NewKit/Stream.hpp
index b615dc77..eefb0a1c 100644
--- a/Kernel/NewKit/Stream.hpp
+++ b/Kernel/NewKit/Stream.hpp
@@ -8,7 +8,7 @@
#pragma once
#include <NewKit/Defines.hpp>
-#include <NewKit/Ref.hpp>
+#include <NewKit/Ref.hxx>
namespace Kernel
{