summaryrefslogtreecommitdiffhomepage
path: root/dev/lib/memory
diff options
context:
space:
mode:
authorAmlal El Mahrouss <amlal@nekernel.org>2025-08-01 09:09:57 +0100
committerAmlal El Mahrouss <amlal@nekernel.org>2025-08-01 09:09:57 +0100
commit284708d1e8a14867b5276a8e760588d8531835d8 (patch)
tree9f651db6d8b51bf97f2fd2fb41efbf5e53498eea /dev/lib/memory
parent574d373163f7edade42e935b9e6957cdaf08d94b (diff)
feat: generic: new `except` module, network model for FIX, and tracked_ptr improvements.
feat: introduce the `must_pass` concept to validate a container. Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'dev/lib/memory')
-rw-r--r--dev/lib/memory/tracked_ptr.hpp23
1 files changed, 22 insertions, 1 deletions
diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp
index b7e55f7..1ff4cca 100644
--- a/dev/lib/memory/tracked_ptr.hpp
+++ b/dev/lib/memory/tracked_ptr.hpp
@@ -31,6 +31,13 @@ namespace snu::memory
std::atomic<size_t> deallocated_count_ = 0;
public:
+ explicit tracked_allocator() = default;
+ virtual ~tracked_allocator() = default;
+
+ tracked_allocator& operator=(const tracked_allocator&) = default;
+ tracked_allocator(const tracked_allocator&) = default;
+
+ public:
template <typename... U>
void retain(T*& ptr, U&&... args)
{
@@ -68,6 +75,13 @@ namespace snu::memory
tracked_allocator<T> allocator_;
public:
+ explicit tracked_mgr() = default;
+ virtual ~tracked_mgr() = default;
+
+ tracked_mgr& operator=(const tracked_mgr&) = default;
+ tracked_mgr(const tracked_mgr&) = default;
+
+ public:
const tracked_allocator<T>& allocator() noexcept
{
return allocator_;
@@ -105,7 +119,7 @@ namespace snu::memory
ptr_ = tracked_ptr::manager().retain(std::forward<U>(args)...);
}
- ~tracked_ptr() noexcept
+ virtual ~tracked_ptr() noexcept
{
this->reset();
}
@@ -192,4 +206,11 @@ namespace snu::memory
{
a.swap(b);
}
+
+ /// @brief a Must Pass function is a standard way to verify a container' validity, inspired from NeKernel/VMKernel.
+ template <typename T>
+ inline void must_pass(tracked_ptr<T>& ptr) noexcept
+ {
+ assert(ptr.manager().allocator().allocated_count_ < ptr.manager().allocator().deallocated_count_);
+ }
} // namespace snu::memory \ No newline at end of file