Use singleton object for accessing Genode's environment.

This commit is contained in:
Michael Müller
2022-07-07 16:55:03 +02:00
parent a9cf438fe5
commit 561fa9d562
3 changed files with 17 additions and 8 deletions

View File

@@ -63,7 +63,7 @@ public:
EpochManager(const std::uint16_t count_channels, dynamic::Allocator &allocator,
util::maybe_atomic<bool> &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<epoch_t> _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<LocalEpoch, tasking::config::max_cores()> _local_epochs;

View File

@@ -1,5 +1,5 @@
#pragma once
#include <base/component.h>
#include <libc/component.h>
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.

View File

@@ -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