Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 22 additions & 16 deletions FEXCore/Source/Interface/Config/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,24 @@ enum Paths {
PATH_CONFIG_TELEMETRY_FOLDER,
PATH_LAST,
};
static std::array<fextl::string, Paths::PATH_LAST> Paths;
using PathsType = std::array<fextl::string, Paths::PATH_LAST>;
static PathsType* Paths {};
alignas(alignof(PathsType)) static char PathsPlacement[sizeof(PathsType)];

void SetDataDirectory(const std::string_view Path, bool Global) {
Paths[PATH_DATA_DIR_LOCAL + Global] = Path;
(*Paths)[PATH_DATA_DIR_LOCAL + Global] = Path;
}

void SetConfigDirectory(const std::string_view Path, bool Global) {
Paths[PATH_CONFIG_DIR_LOCAL + Global] = Path;
(*Paths)[PATH_CONFIG_DIR_LOCAL + Global] = Path;
}

void SetConfigFileLocation(const std::string_view Path, bool Global) {
Paths[PATH_CONFIG_FILE_LOCAL + Global] = Path;
(*Paths)[PATH_CONFIG_FILE_LOCAL + Global] = Path;
}

const fextl::string& GetTelemetryDirectory() {
auto& Path = Paths[PATH_CONFIG_TELEMETRY_FOLDER];
auto& Path = (*Paths)[PATH_CONFIG_TELEMETRY_FOLDER];
if (Path.empty()) {
FEX_CONFIG_OPT(TelemetryDirectory, TELEMETRYDIRECTORY);
if (!TelemetryDirectory().empty()) {
Expand All @@ -79,15 +81,15 @@ const fextl::string& GetTelemetryDirectory() {
}

const fextl::string& GetDataDirectory(bool Global) {
return Paths[PATH_DATA_DIR_LOCAL + Global];
return (*Paths)[PATH_DATA_DIR_LOCAL + Global];
}

const fextl::string& GetConfigDirectory(bool Global) {
return Paths[PATH_CONFIG_DIR_LOCAL + Global];
return (*Paths)[PATH_CONFIG_DIR_LOCAL + Global];
}

const fextl::string& GetConfigFileLocation(bool Global) {
return Paths[PATH_CONFIG_FILE_LOCAL + Global];
return (*Paths)[PATH_CONFIG_FILE_LOCAL + Global];
}

fextl::string GetApplicationConfig(const std::string_view Program, bool Global) {
Expand All @@ -110,7 +112,9 @@ fextl::string GetApplicationConfig(const std::string_view Program, bool Global)
return fextl::fmt::format("{}{}.json", ConfigFile, Program);
}

static fextl::map<FEXCore::Config::LayerType, fextl::unique_ptr<FEXCore::Config::Layer>> ConfigLayers;
using ConfigLayerType = fextl::map<FEXCore::Config::LayerType, fextl::unique_ptr<FEXCore::Config::Layer>>;
static ConfigLayerType* ConfigLayers;
alignas(alignof(ConfigLayerType)) static char ConfigLayersPlacement[sizeof(ConfigLayerType)];
class MetaLayer;
static FEXCore::Config::MetaLayer* Meta {};

Expand Down Expand Up @@ -172,8 +176,8 @@ void MetaLayer::Load() {
OptionMap.clear();

for (auto CurrentLayer = LoadOrder.begin(); CurrentLayer != LoadOrder.end(); ++CurrentLayer) {
auto it = ConfigLayers.find(*CurrentLayer);
if (it != ConfigLayers.end() && *CurrentLayer != Type) {
auto it = ConfigLayers->find(*CurrentLayer);
if (it != ConfigLayers->end() && *CurrentLayer != Type) {
// Merge this layer's options to this layer
MergeConfigMap(it->second->GetOptionMap());
}
Expand Down Expand Up @@ -234,19 +238,21 @@ void MetaLayer::MergeConfigMap(const LayerOptions& Options) {
}

void Initialize() {
Paths = new (PathsPlacement) PathsType {};
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does it need placement new here instead of plain new?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plain new causes glibc allocation to occur, and this also gives a nicety of static allocation still.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we can just take FEXCore::Allocator or whatever it is that we normally use instead of new, right?

a nicety of static allocation still

Does this translate to any practical benefit? I'd rather we keep the code as complex as needed only if not.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. Static allocation duration so we aren't mixing allocators.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How would we be mixing allocators if we just used FEXCore::Allocator instead?

ConfigLayers = new (ConfigLayersPlacement) ConfigLayerType {};
AddLayer(fextl::make_unique<MetaLayer>(FEXCore::Config::LayerType::LAYER_TOP));
Meta = dynamic_cast<MetaLayer*>(ConfigLayers.begin()->second.get());
Meta = dynamic_cast<MetaLayer*>(ConfigLayers->begin()->second.get());
}

void Shutdown() {
ConfigLayers.clear();
ConfigLayers->clear();
Meta = nullptr;
}

void Load() {
for (auto CurrentLayer = LoadOrder.begin(); CurrentLayer != LoadOrder.end(); ++CurrentLayer) {
auto it = ConfigLayers.find(*CurrentLayer);
if (it != ConfigLayers.end()) {
auto it = ConfigLayers->find(*CurrentLayer);
if (it != ConfigLayers->end()) {
it->second->Load();
}
}
Expand Down Expand Up @@ -412,7 +418,7 @@ void ReloadMetaLayer() {
}

void AddLayer(fextl::unique_ptr<FEXCore::Config::Layer> _Layer) {
ConfigLayers.emplace(_Layer->GetLayerType(), std::move(_Layer));
ConfigLayers->emplace(_Layer->GetLayerType(), std::move(_Layer));
}

bool Exists(ConfigOption Option) {
Expand Down
2 changes: 1 addition & 1 deletion Source/Common/Config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,8 @@ ApplicationNames GetApplicationNames(const fextl::vector<fextl::string>& Args, b

void LoadConfig(fextl::string ProgramName, char** const envp, const PortableInformation& PortableInfo) {
const bool IsPortable = PortableInfo.IsPortable;
FEX::Config::InitializeConfigs(PortableInfo);
FEXCore::Config::Initialize();
FEX::Config::InitializeConfigs(PortableInfo);
if (!IsPortable) {
FEXCore::Config::AddLayer(CreateGlobalMainLayer());
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Tools/FEXGetConfig/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ TSOEmulationFacts GetTSOEmulationFacts() {
} // namespace

int main(int argc, char** argv, char** envp) {
FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::Initialize();
FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::AddLayer(FEX::Config::CreateGlobalMainLayer());
FEXCore::Config::AddLayer(FEX::Config::CreateMainLayer());
// No FEX arguments passed through command line
Expand Down
2 changes: 1 addition & 1 deletion Source/Tools/TestHarnessRunner/TestHarnessRunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ int main(int argc, char** argv, char** const envp) {
LogMan::Throw::InstallHandler(AssertHandler);
LogMan::Msg::InstallHandler(MsgHandler);

FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::Initialize();
FEX::Config::InitializeConfigs(FEX::Config::PortableInformation {});
FEXCore::Config::AddLayer(FEX::Config::CreateEnvironmentLayer(envp));
FEXCore::Config::Load();

Expand Down
Loading