From 5e59f1872064835f3747a311e7090ae16dab7925 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Wed, 26 Feb 2020 20:43:27 +0300 Subject: [PATCH] fixed_typemap: implement need<> method It may be used in constructors of other objects to assert a dependency. It also helps to ensure reverse destruction order of that dependency. --- rpcs3/Emu/VFS.cpp | 7 ++----- rpcs3/util/fixed_typemap.hpp | 10 ++++++++++ 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/rpcs3/Emu/VFS.cpp b/rpcs3/Emu/VFS.cpp index 9408285aab..cbc665eb07 100644 --- a/rpcs3/Emu/VFS.cpp +++ b/rpcs3/Emu/VFS.cpp @@ -29,11 +29,8 @@ struct vfs_manager bool vfs::mount(std::string_view vpath, std::string_view path) { - if (!g_fxo->get()) - { - // Init (TODO) - g_fxo->init(); - } + // Workaround + g_fxo->need(); const auto table = g_fxo->get(); diff --git a/rpcs3/util/fixed_typemap.hpp b/rpcs3/util/fixed_typemap.hpp index 197d22eeb4..8aa3274e98 100644 --- a/rpcs3/util/fixed_typemap.hpp +++ b/rpcs3/util/fixed_typemap.hpp @@ -148,6 +148,16 @@ namespace stx } } + // Check if object is not initialized but shall be initialized first (to use in initializing other objects) + template + void need() noexcept + { + if (!get()) + { + init(); + } + } + // Explicitly (re)initialize object of type T possibly with dynamic type As and arguments template As* init(Args&&... args) noexcept