From 561fa9d562e8e4c62547113658a7f0d1582d2166 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20M=C3=BCller?= Date: Thu, 7 Jul 2022 16:55:03 +0200 Subject: [PATCH] Use singleton object for accessing Genode's environment. --- src/mx/memory/reclamation/epoch_manager.h | 4 ++-- src/mx/system/environment.h | 19 ++++++++++++++----- src/mx/system/topology.h | 2 +- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/mx/memory/reclamation/epoch_manager.h b/src/mx/memory/reclamation/epoch_manager.h index 496641b..eabe7c5 100644 --- a/src/mx/memory/reclamation/epoch_manager.h +++ b/src/mx/memory/reclamation/epoch_manager.h @@ -63,7 +63,7 @@ public: EpochManager(const std::uint16_t count_channels, dynamic::Allocator &allocator, util::maybe_atomic &is_running) noexcept : - Thread(*system::Environment::env, Name("EpochManager"), 8192), + Thread(*system::Environment::env(), Name("EpochManager"), 8192), _count_channels(count_channels), _is_running(is_running), _allocator(allocator) { } @@ -159,7 +159,7 @@ private: std::atomic _global_epoch{0U}; // Genode Timer object, needed for waking up periodically - Timer::Connection _timer { *system::Environment::env }; + Timer::Connection _timer { *system::Environment::env() }; // Local epochs, one for every channel. alignas(64) std::array _local_epochs; diff --git a/src/mx/system/environment.h b/src/mx/system/environment.h index 7d51d47..3f2121a 100644 --- a/src/mx/system/environment.h +++ b/src/mx/system/environment.h @@ -1,5 +1,5 @@ #pragma once -#include +#include namespace mx::system { /** @@ -7,15 +7,24 @@ namespace mx::system { */ class Environment { -public: - +private: /** * @return Genode environment capability * */ - static Genode::Env *env; + Libc::Env *_env; - +public: + Environment() = default; + + Libc::Env *getenv() { return _env; } + void setenv(Libc::Env *env) { Environment::get_instance().setenv(env); } + + static Environment& get_instance() { static Environment env; + return env; + } + + static Libc::Env *env() { return Environment::get_instance().getenv(); } /** * @return True, if NUMA balancing is enabled by the system. diff --git a/src/mx/system/topology.h b/src/mx/system/topology.h index f53ec88..9af25a6 100644 --- a/src/mx/system/topology.h +++ b/src/mx/system/topology.h @@ -36,7 +36,7 @@ public: /** * @return Number of available cores. */ - static std::uint16_t count_cores() { return std::uint16_t(Environment::env->cpu().affinity_space().total()); + static std::uint16_t count_cores() { return std::uint16_t(Environment::env()->cpu().affinity_space().total()); } }; } // namespace mx::system \ No newline at end of file