mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2026-11-12 09:10:21 +01:00
core: Prevent uninitialized start_time and race in UpdatePlayTime (#5142)
This commit is contained in:
1 parent
cc3d367ec7
commit
5ea46a6741
1 file changed
+12
-4
+12
-4
@@ -92,6 +92,10 @@ void Emulator::Shutdown() {
|
||||
Common::Log::Flush();
|
||||
Libraries::SaveData::Backup::StopThread();
|
||||
Storage::DataBase::Instance().Close();
|
||||
play_time_thread.request_stop();
|
||||
if (play_time_thread.joinable()) {
|
||||
play_time_thread.join();
|
||||
}
|
||||
UpdatePlayTime(Common::Singleton<Common::ElfInfo>::Instance()->GameSerial());
|
||||
if (controllers) {
|
||||
controllers->ResetLightbarColors();
|
||||
@@ -688,7 +692,6 @@ void Emulator::Run(std::filesystem::path file, std::vector<std::string> args,
|
||||
play_time_thread = std::jthread([this, id](std::stop_token stop) {
|
||||
while (Common::StoppableTimedWait(stop, std::chrono::seconds(60))) {
|
||||
UpdatePlayTime(id);
|
||||
start_time = std::chrono::steady_clock::now();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -834,6 +837,10 @@ void Emulator::Restart(std::filesystem::path eboot_path,
|
||||
}
|
||||
|
||||
void Emulator::UpdatePlayTime(const std::string_view serial) {
|
||||
if (serial.empty() || start_time == std::chrono::steady_clock::time_point{}) {
|
||||
return;
|
||||
}
|
||||
|
||||
const auto user_dir = Common::FS::GetUserPath(Common::FS::PathType::UserDir);
|
||||
const auto filePath = (user_dir / "play_time.txt").string();
|
||||
|
||||
@@ -843,9 +850,10 @@ void Emulator::UpdatePlayTime(const std::string_view serial) {
|
||||
return;
|
||||
}
|
||||
|
||||
auto end_time = std::chrono::steady_clock::now();
|
||||
auto duration = std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time);
|
||||
int total_seconds = static_cast<int>(duration.count());
|
||||
const auto end_time = std::chrono::steady_clock::now();
|
||||
const auto duration = std::chrono::duration_cast<std::chrono::seconds>(end_time - start_time);
|
||||
start_time = end_time;
|
||||
const int total_seconds = static_cast<int>(duration.count());
|
||||
|
||||
std::vector<std::string> lines;
|
||||
std::string line;
|
||||
|
||||
Reference in new issue
Block a user