summaryrefslogtreecommitdiffstats
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2022-09-06 02:55:51 +0200
committerbunnei <bunneidev@gmail.com>2022-10-19 04:13:34 +0200
commitd02ccfb15d1f3d4fcdb9feae60ae136fcfd99788 (patch)
treeca5323fb1ec68352354b6c9c1653f7f36fbab815 /src/core/hle/kernel
parentcore: hle: kernel: Add KDynamicSlabHeap. (diff)
downloadyuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar.gz
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar.bz2
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar.lz
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar.xz
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.tar.zst
yuzu-d02ccfb15d1f3d4fcdb9feae60ae136fcfd99788.zip
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/k_dynamic_resource_manager.h58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/core/hle/kernel/k_dynamic_resource_manager.h b/src/core/hle/kernel/k_dynamic_resource_manager.h
new file mode 100644
index 000000000..1ce517e8e
--- /dev/null
+++ b/src/core/hle/kernel/k_dynamic_resource_manager.h
@@ -0,0 +1,58 @@
+// SPDX-FileCopyrightText: Copyright 2022 yuzu Emulator Project
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+#pragma once
+
+#include "common/common_funcs.h"
+#include "core/hle/kernel/k_dynamic_slab_heap.h"
+#include "core/hle/kernel/k_memory_block.h"
+
+namespace Kernel {
+
+template <typename T, bool ClearNode = false>
+class KDynamicResourceManager {
+ YUZU_NON_COPYABLE(KDynamicResourceManager);
+ YUZU_NON_MOVEABLE(KDynamicResourceManager);
+
+public:
+ using DynamicSlabType = KDynamicSlabHeap<T, ClearNode>;
+
+public:
+ constexpr KDynamicResourceManager() = default;
+
+ constexpr size_t GetSize() const {
+ return m_slab_heap->GetSize();
+ }
+ constexpr size_t GetUsed() const {
+ return m_slab_heap->GetUsed();
+ }
+ constexpr size_t GetPeak() const {
+ return m_slab_heap->GetPeak();
+ }
+ constexpr size_t GetCount() const {
+ return m_slab_heap->GetCount();
+ }
+
+ void Initialize(KDynamicPageManager* page_allocator, DynamicSlabType* slab_heap) {
+ m_page_allocator = page_allocator;
+ m_slab_heap = slab_heap;
+ }
+
+ T* Allocate() const {
+ return m_slab_heap->Allocate(m_page_allocator);
+ }
+
+ void Free(T* t) const {
+ m_slab_heap->Free(t);
+ }
+
+private:
+ KDynamicPageManager* m_page_allocator{};
+ DynamicSlabType* m_slab_heap{};
+};
+
+class KMemoryBlockSlabManager : public KDynamicResourceManager<KMemoryBlock> {};
+
+using KMemoryBlockSlabHeap = typename KMemoryBlockSlabManager::DynamicSlabType;
+
+} // namespace Kernel