diff --git a/src/mx/memory/global_heap.h b/src/mx/memory/global_heap.h index 01f0566..163a57e 100644 --- a/src/mx/memory/global_heap.h +++ b/src/mx/memory/global_heap.h @@ -13,10 +13,19 @@ namespace mx::memory { class GlobalHeap { private: - static Genode::Heap _heap; + Genode::Heap _heap; public: - static Genode::Heap &heap() { return _heap; } + GlobalHeap() : _heap(Genode::Heap(system::Environment::env()->ram(), system::Environment::env()->rm())) {} + + Genode::Heap &get_heap() { return _heap; } + + static GlobalHeap &get_instance() { + static GlobalHeap gheap; + return gheap; + } + + static Genode::Heap &heap() { return GlobalHeap::get_instance().get_heap(); } /** * Allocates the given size on the given NUMA node. @@ -28,7 +37,7 @@ public: static void *allocate(const std::uint8_t numa_node_id, const std::size_t size) { /* TODO: Use component's heap */ - _heap.alloc(size); + return GlobalHeap::get_instance().heap().alloc(size); } /** @@ -41,7 +50,7 @@ public: static void *allocate_cache_line_aligned(const std::size_t size) { /* TODO: Use component's heap, as std::aligned_alloc might not be thread-safe */ - return _heap.alloc(alignment_helper::next_multiple(size, 64UL)); + return GlobalHeap::get_instance().heap().alloc(alignment_helper::next_multiple(size, 64UL)); } /** @@ -51,7 +60,7 @@ public: * @param size Size of the allocated object. */ static void free(void *memory, const std::size_t size) { /* TODO: Free via Genode component's heap */ - _heap.free(memory, size); + GlobalHeap::heap().free(memory, size); } }; } // namespace mx::memory \ No newline at end of file diff --git a/src/mx/tasking/profiling/profiling_task.cpp b/src/mx/tasking/profiling/profiling_task.cpp index 033fff2..8d7f135 100644 --- a/src/mx/tasking/profiling/profiling_task.cpp +++ b/src/mx/tasking/profiling/profiling_task.cpp @@ -7,7 +7,7 @@ using namespace mx::tasking::profiling; ProfilingTask::ProfilingTask(mx::util::maybe_atomic &is_running, mx::tasking::Channel &channel) - : _is_running(is_running), _channel(channel), _timer (*new (memory::GlobalHeap::heap())Timer::Connection(*system::Environment::env)) + : _is_running(is_running), _channel(channel), _timer (*new (memory::GlobalHeap::heap()) Timer::Connection(*system::Environment::env())) { _idle_ranges.reserve(1 << 16); } diff --git a/src/mx/tasking/worker.cpp b/src/mx/tasking/worker.cpp index 94d76ef..e4b9da2 100644 --- a/src/mx/tasking/worker.cpp +++ b/src/mx/tasking/worker.cpp @@ -13,7 +13,7 @@ Worker::Worker(const std::uint16_t id, const std::uint16_t target_core_id, const const util::maybe_atomic &is_running, const std::uint16_t prefetch_distance, memory::reclamation::LocalEpoch &local_epoch, const std::atomic &global_epoch, profiling::Statistic &statistic) noexcept - : Thread(*system::Environment::env, Name("Worker ", id), 4*4096, system::Environment::env->cpu().affinity_space().location_of_index(target_core_id), Weight(), system::Environment::env->cpu()), + : Thread(*system::Environment::env(), Name("Worker ", id), 4*4096, system::Environment::env()->cpu().affinity_space().location_of_index(target_core_id), Weight(), system::Environment::env()->cpu()), _target_core_id(target_core_id), _prefetch_distance(prefetch_distance), _channel(id, target_numa_node_id, prefetch_distance), _local_epoch(local_epoch), _global_epoch(global_epoch), _statistic(statistic), _is_running(is_running)