safe save backup shutdown

replaced exit by quick_exit
This commit is contained in:
Vinicius Rangel 2025-01-30 04:19:18 -03:00
parent 9fa5014d16
commit 33cd65281d
No known key found for this signature in database
GPG Key ID: A5B154D904B761D9
2 changed files with 12 additions and 2 deletions

View File

@ -143,6 +143,15 @@ void StartThread() {
LOG_DEBUG(Lib_SaveData, "Starting backup thread");
g_backup_status = WorkerStatus::Waiting;
g_backup_thread = std::jthread{BackupThreadBody};
static std::once_flag flag;
std::call_once(flag, [] {
std::at_quick_exit([] {
StopThread();
while (GetWorkerStatus() != WorkerStatus::NotStarted) {
std::this_thread::sleep_for(std::chrono::milliseconds(100));
}
});
});
}
void StopThread() {
@ -150,12 +159,12 @@ void StopThread() {
return;
}
LOG_DEBUG(Lib_SaveData, "Stopping backup thread");
g_backup_status = WorkerStatus::Stopping;
{
std::scoped_lock lk{g_backup_queue_mutex};
g_backup_queue.emplace_back(BackupRequest{});
}
g_backup_thread_semaphore.release();
g_backup_status = WorkerStatus::Stopping;
}
bool NewRequest(OrbisUserServiceUserId user_id, std::string_view title_id,

View File

@ -33,6 +33,7 @@
#include "core/libraries/ngs2/ngs2.h"
#include "core/libraries/np_trophy/np_trophy.h"
#include "core/libraries/rtc/rtc.h"
#include "core/libraries/save_data/save_backup.h"
#include "core/linker.h"
#include "core/memory.h"
#include "emulator.h"
@ -259,7 +260,7 @@ void Emulator::Run(const std::filesystem::path& file, const std::vector<std::str
UpdatePlayTime(id);
#endif
std::exit(0);
std::quick_exit(0);
}
void Emulator::LoadSystemModules(const std::string& game_serial) {