From 405b5b1018397bff48e32c75e10a6b3b58bb6a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matteo=20Gm=C3=BCr?= Date: Fri, 21 Feb 2025 14:13:39 +0000 Subject: Update factory method code --- .../include/arch/memory/heap/bump_allocator.hpp | 4 ++-- arch/x86_64/include/arch/memory/heap/concept.hpp | 22 ---------------------- .../arch/memory/heap/global_heap_allocator.hpp | 8 ++++---- .../include/arch/memory/heap/heap_allocator.hpp | 5 +++++ 4 files changed, 11 insertions(+), 28 deletions(-) delete mode 100644 arch/x86_64/include/arch/memory/heap/concept.hpp (limited to 'arch/x86_64/include') diff --git a/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp b/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp index 209f8b3..d5f4561 100644 --- a/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/bump_allocator.hpp @@ -34,7 +34,7 @@ namespace teachos::arch::memory::heap * @param size Amount of memory to allocate. * @return Address of the first byte to the allocated area */ - auto allocate(std::size_t size) -> void *; + auto allocate(std::size_t size) -> void * override; /** * @brief Deallocates heap memory at the specified location. @@ -44,7 +44,7 @@ namespace teachos::arch::memory::heap * @param pointer Pointer to the location which should be deallocated. * @param size Size of the underlying memory area we want to deallocate. */ - auto deallocate(void * pointer, std::size_t size) -> void; + auto deallocate(void * pointer, std::size_t size) -> void override; private: std::size_t heap_start; ///< Start of the allocatable heap area diff --git a/arch/x86_64/include/arch/memory/heap/concept.hpp b/arch/x86_64/include/arch/memory/heap/concept.hpp deleted file mode 100644 index e22e35f..0000000 --- a/arch/x86_64/include/arch/memory/heap/concept.hpp +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP -#define TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP - -#include - -namespace teachos::arch::memory::heap -{ - std::size_t constexpr HEAP_START = 0x100000000; - std::size_t constexpr HEAP_SIZE = 100 * 1024; - - /** - * @brief Heap allocator concept required for allocating and managing free space on the heap. - */ - template - concept HeapAllocator = requires(T t, uint8_t * pointer, std::size_t size) { - { t.allocate(size) } -> std::same_as; - { t.deallocate(pointer, size) } -> std::same_as; - }; - -} // namespace teachos::arch::memory::heap - -#endif // TEACHOS_ARCH_X86_64_MEMORY_HEAP_CONCEPT_HPP diff --git a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp index e8555df..1b1d964 100644 --- a/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp @@ -1,7 +1,7 @@ #ifndef TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP #define TEACHOS_ARCH_X86_64_MEMORY_HEAP_GLOBAL_HEAP_ALLOCATOR_HPP -#include "arch/memory/heap/linked_list_allocator.hpp" +#include "arch/memory/heap/heap_allocator.hpp" namespace teachos::arch::memory::heap { @@ -14,16 +14,16 @@ namespace teachos::arch::memory::heap struct global_heap_allocator { - static auto register_heap_allocator_type(heap_allocator_type new_type) -> void; + static auto register_heap_allocator(heap_allocator_type new_type) -> void; static auto allocate(std::size_t size) -> void *; static auto deallocate(void * pointer, std::size_t size) -> void; private: - static heap_allocator_type allocator_type; + static heap_allocator * allocator_instance; - static auto create_or_get() -> heap_allocator &; + static auto get() -> heap_allocator &; }; } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp b/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp index 9e37bd4..62ba963 100644 --- a/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp +++ b/arch/x86_64/include/arch/memory/heap/heap_allocator.hpp @@ -5,8 +5,13 @@ namespace teachos::arch::memory::heap { + std::size_t constexpr HEAP_START = 0x100000000; + std::size_t constexpr HEAP_SIZE = 100 * 1024; + struct heap_allocator { + virtual ~heap_allocator() {} + virtual auto allocate(std::size_t size) -> void * = 0; virtual auto deallocate(void * pointer, std::size_t size) -> void = 0; -- cgit v1.2.3