aboutsummaryrefslogtreecommitdiff
path: root/src/core/core.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/core.cpp')
-rw-r--r--src/core/core.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index ba4629993..bb268a319 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -83,6 +83,12 @@ FileSys::StorageId GetStorageIdForFrontendSlot(
}
}
+void KProcessDeleter(Kernel::KProcess* process) {
+ process->Destroy();
+}
+
+using KProcessPtr = std::unique_ptr<Kernel::KProcess, decltype(&KProcessDeleter)>;
+
} // Anonymous namespace
FileSys::VirtualFile GetGameFileFromPath(const FileSys::VirtualFilesystem& vfs,
@@ -233,8 +239,8 @@ struct System::Impl {
}
telemetry_session->AddInitialInfo(*app_loader, fs_controller, *content_provider);
- auto main_process = Kernel::KProcess::Create(system.Kernel());
- ASSERT(Kernel::KProcess::Initialize(main_process, system, "main",
+ main_process = KProcessPtr{Kernel::KProcess::Create(system.Kernel()), KProcessDeleter};
+ ASSERT(Kernel::KProcess::Initialize(main_process.get(), system, "main",
Kernel::KProcess::ProcessType::Userland)
.IsSuccess());
main_process->Open();
@@ -247,7 +253,7 @@ struct System::Impl {
static_cast<u32>(load_result));
}
AddGlueRegistrationForProcess(*app_loader, *main_process);
- kernel.MakeCurrentProcess(main_process);
+ kernel.MakeCurrentProcess(main_process.get());
kernel.InitializeCores();
// Initialize cheat engine
@@ -299,10 +305,6 @@ struct System::Impl {
is_powered_on = false;
exit_lock = false;
- if (gpu_core) {
- gpu_core->ShutDown();
- }
-
services.reset();
service_manager.reset();
cheat_engine.reset();
@@ -311,11 +313,13 @@ struct System::Impl {
time_manager.Shutdown();
core_timing.Shutdown();
app_loader.reset();
- gpu_core.reset();
perf_stats.reset();
+ gpu_core.reset();
kernel.Shutdown();
memory.Reset();
applet_manager.ClearAll();
+ // TODO: The main process should be freed based on KAutoObject ref counting.
+ main_process.reset();
LOG_DEBUG(Core, "Shutdown OK");
}
@@ -374,6 +378,7 @@ struct System::Impl {
std::unique_ptr<Tegra::GPU> gpu_core;
std::unique_ptr<Hardware::InterruptManager> interrupt_manager;
std::unique_ptr<Core::DeviceMemory> device_memory;
+ KProcessPtr main_process{nullptr, KProcessDeleter};
Core::Memory::Memory memory;
CpuManager cpu_manager;
std::atomic_bool is_powered_on{};
@@ -416,6 +421,7 @@ struct System::Impl {
bool is_async_gpu{};
ExecuteProgramCallback execute_program_callback;
+ ExitCallback exit_callback;
std::array<u64, Core::Hardware::NUM_CPU_CORES> dynarmic_ticks{};
std::array<MicroProfileToken, Core::Hardware::NUM_CPU_CORES> microprofile_dynarmic{};
@@ -793,6 +799,18 @@ void System::ExecuteProgram(std::size_t program_index) {
}
}
+void System::RegisterExitCallback(ExitCallback&& callback) {
+ impl->exit_callback = std::move(callback);
+}
+
+void System::Exit() {
+ if (impl->exit_callback) {
+ impl->exit_callback();
+ } else {
+ LOG_CRITICAL(Core, "exit_callback must be initialized by the frontend");
+ }
+}
+
void System::ApplySettings() {
if (IsPoweredOn()) {
Renderer().RefreshBaseSettings();