diff options
| author | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-02-20 10:58:17 +0000 |
|---|---|---|
| committer | Matteo Gmür <matteo.gmuer1@ost.ch> | 2025-02-20 10:58:17 +0000 |
| commit | cd502936227e48a36d9e933d26aac2ee29d3bc29 (patch) | |
| tree | 9fe872f2c088964465acd51d5e6e54e15570b9d1 | |
| parent | 6c4ce82c3f9cc920bcde74fc10fdfd39b477b9f4 (diff) | |
| download | teachos-cd502936227e48a36d9e933d26aac2ee29d3bc29.tar.xz teachos-cd502936227e48a36d9e933d26aac2ee29d3bc29.zip | |
Add singelton implementation for global heap allocator
| -rw-r--r-- | arch/x86_64/include/arch/memory/heap/global_heap_allocator.hpp | 2 | ||||
| -rw-r--r-- | arch/x86_64/src/memory/heap/global_heap_allocator.cpp | 12 |
2 files changed, 9 insertions, 5 deletions
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 871f4f8..f391936 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 @@ -12,7 +12,7 @@ namespace teachos::arch::memory::heap static auto deallocate(void * pointer, std::size_t size) -> void; private: - static linked_list_allocator allocator; + static auto get_underlying_allocator() -> linked_list_allocator &; }; } // namespace teachos::arch::memory::heap diff --git a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp index 11848ed..4e3a274 100644 --- a/arch/x86_64/src/memory/heap/global_heap_allocator.cpp +++ b/arch/x86_64/src/memory/heap/global_heap_allocator.cpp @@ -5,13 +5,17 @@ namespace teachos::arch::memory::heap { - static global_heap_allocator::allocator = linked_list_allocator{HEAP_START, HEAP_START + HEAP_SIZE}; - - auto global_heap_allocator::allocate(std::size_t size) -> void * { return allocator.allocate(size); } + auto global_heap_allocator::allocate(std::size_t size) -> void * { return get_underlying_allocator().allocate(size); } auto global_heap_allocator::deallocate(void * pointer, std::size_t size) -> void { - allocator.deallocate(pointer, size); + get_underlying_allocator().deallocate(pointer, size); + } + + auto global_heap_allocator::get_underlying_allocator() -> linked_list_allocator & + { + static linked_list_allocator allocator{HEAP_START, HEAP_START + HEAP_SIZE}; + return allocator; } } // namespace teachos::arch::memory::heap |
