From 65a8349aa5526d071b18cd4d42586c46faaa3823 Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 24 Nov 2025 02:13:48 +0100 Subject: feat! breaking changes for OCL v1.0.48. Signed-off-by: Amlal El Mahrouss --- dev/lib/memory/allocator_system.hpp | 74 ------------ dev/lib/memory/tracked_ptr.hpp | 235 ------------------------------------ 2 files changed, 309 deletions(-) delete mode 100644 dev/lib/memory/allocator_system.hpp delete mode 100644 dev/lib/memory/tracked_ptr.hpp (limited to 'dev/lib/memory') diff --git a/dev/lib/memory/allocator_system.hpp b/dev/lib/memory/allocator_system.hpp deleted file mode 100644 index 0fe7af3..0000000 --- a/dev/lib/memory/allocator_system.hpp +++ /dev/null @@ -1,74 +0,0 @@ -/* - * File: core/allocator_system.hpp - * Purpose: Allocator System container. - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, Licensed under the Boost Software License. Licensed under the BSL 1.0 license - */ - -#ifndef _OCL_ALLOCATOR_SYSTEM_HPP -#define _OCL_ALLOCATOR_SYSTEM_HPP - -#include -#include - -namespace ocl -{ - template - struct new_op final - { - inline auto operator()() -> type* - { - return new type; - } - - template - inline auto var_alloc(var_type... args) -> type* - { - return new type{args...}; - } - }; - - template - struct delete_op final - { - inline auto operator()(type* t) -> void - { - delete t; - } - }; - - template - class allocator_system - { - allocator_new m_alloc_{}; - allocator_delete m_free_{}; - - public: - allocator_system() = default; - ~allocator_system() = default; - - allocator_system& operator=(const allocator_system&) = delete; - allocator_system(const allocator_system&) = delete; - - ret_type* claim() noexcept - { - return m_alloc_(); - } - - template - auto construct(var_type... args) -> std::shared_ptr - { - return std::shared_ptr(m_alloc_.template var_alloc(args...), allocator_delete{}); - } - - void unclaim(ret_type* ptr) - { - m_free_(ptr); - } - }; - - template - using standard_allocator_type = allocator_system, delete_op>; -} // namespace ocl - -#endif // ifndef _OCL_ALLOCATOR_SYSTEM_HPP \ No newline at end of file diff --git a/dev/lib/memory/tracked_ptr.hpp b/dev/lib/memory/tracked_ptr.hpp deleted file mode 100644 index 2df5db5..0000000 --- a/dev/lib/memory/tracked_ptr.hpp +++ /dev/null @@ -1,235 +0,0 @@ -/* - * File: memory/tracked_ptr.hpp - * Purpose: Custom smart pointer implementation in C++ - * Author: Amlal El Mahrouss (amlal@nekernel.org) - * Copyright 2025, Amlal El Mahrouss, licensed under the Boost Software License. - */ - -#pragma once - -#include -#include -#include -#include - -#include -#include -#include - -namespace ocl::memory -{ - template - class tracked_allocator; - - template - class tracked_mgr; - - template - class tracked_ptr; - - template - class tracked_allocator - { - public: - std::atomic allocated_count_ = 0; - std::atomic 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 - void retain(T*& ptr, U&&... args) - { - ptr = new T(std::forward(args)...); - - if (ptr) - { - ++allocated_count_; - return; - } - - throw std::bad_alloc(); - } - - template - void must_retain(T*& ptr, U&&... args) noexcept - { - this->retain(ptr, args...); - } - - void dispose(T*& ptr) noexcept - { - if (ptr) - { - if (allocated_count_) - --allocated_count_; - - ++deallocated_count_; - - delete ptr; - ptr = nullptr; - } - } - }; - - template - class tracked_mgr - { - private: - tracked_allocator 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& allocator() noexcept - { - return allocator_; - } - - template - T* retain(U&&... args) - { - T* ptr = nullptr; - allocator_.retain(ptr, std::forward(args)...); - - return ptr; - } - - template - T* must_retain(U&&... args) noexcept - { - return this->retain(std::forward(args)...); - } - - void dispose(T*& ptr) noexcept - { - allocator_.dispose(ptr); - } - }; - - template > - class tracked_ptr - { - public: - static Mgr& manager() noexcept - { - static Mgr mgr; - return mgr; - } - - public: - template - tracked_ptr(U&&... args) - : ptr_(nullptr) - { - ptr_ = tracked_ptr::manager().retain(std::forward(args)...); - } - - virtual ~tracked_ptr() noexcept - { - this->reset(); - } - - tracked_ptr(const tracked_ptr&) = delete; - tracked_ptr& operator=(const tracked_ptr&) = delete; - - public: - void reset() - { - if (ptr_) - { - tracked_ptr::manager().dispose(ptr_); - } - } - - T* get() const - { - return ptr_; - } - - T* data() - { - return ptr_; - } - - T& operator*() const - { - return *ptr_; - } - - T* operator->() const - { - return ptr_; - } - - explicit operator bool() const - { - return ptr_ != nullptr; - } - - void swap(tracked_ptr& other) - { - std::swap(ptr_, other.ptr_); - } - - public: - tracked_ptr(tracked_ptr&& other) noexcept - : ptr_(other.ptr_) - { - other.ptr_ = nullptr; - } - - tracked_ptr& operator=(tracked_ptr&& other) noexcept - { - if (this != &other) - { - this->reset(); - ptr_ = other.ptr_; - other.ptr_ = nullptr; - } - - return *this; - } - - private: - T* ptr_{nullptr}; - }; - - template - inline auto make_tracked() -> tracked_ptr - { - return tracked_ptr(); - } - - template - inline auto make_tracked(T&&... arg) -> tracked_ptr - { - return tracked_ptr(std::forward(arg)...); - } - - template - inline void swap(tracked_ptr& a, tracked_ptr& b) - { - a.swap(b); - } - - /// @brief a Must Pass function is a standard way to verify a container' validity, inspired from NeKernel/VMKernel. - template - inline void must_pass(tracked_ptr& ptr, error_handler handler) - { - if (ptr.manager().allocator().allocated_count_ < ptr.manager().allocator().deallocated_count_) - { - handler.template error("Invalid TrackedPtr detected: Deallocated count exceeds allocated count."); - } - } -} // namespace ocl::memory -- cgit v1.2.3