Skip to content

Commit

Permalink
safe save backup shutdown
Browse files Browse the repository at this point in the history
replaced exit by quick_exit
  • Loading branch information
viniciuslrangel committed Jan 30, 2025
1 parent 8ac781d commit c45d844
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/core/libraries/save_data/save_backup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,19 +143,28 @@ 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() {
if (g_backup_status == WorkerStatus::NotStarted || g_backup_status == WorkerStatus::Stopping) {
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,
Expand Down
3 changes: 2 additions & 1 deletion src/emulator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit c45d844

Please sign in to comment.