diff --git a/rpcs3/Emu/CPU/CPUThread.cpp b/rpcs3/Emu/CPU/CPUThread.cpp index b6e67837a2..2b67d3e2f6 100644 --- a/rpcs3/Emu/CPU/CPUThread.cpp +++ b/rpcs3/Emu/CPU/CPUThread.cpp @@ -437,7 +437,7 @@ void cpu_thread::operator()() } // Can we have a little race, right? First thread is started concurrently with g_fxo->init() - std::this_thread::sleep_for(1ms); + thread_ctrl::wait_for(1000); } switch (id_type()) diff --git a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp index 1c82fcae00..9290a3d6cd 100644 --- a/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp +++ b/rpcs3/Emu/Cell/Modules/cellMsgDialog.cpp @@ -104,7 +104,7 @@ struct msg_dlg_thread_info if (wait_until.load() != new_value) break; - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10'000); } if (auto manager = g_fxo->get()) diff --git a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp index be6bab3a60..f003fa37b2 100644 --- a/rpcs3/Emu/Cell/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/Cell/Modules/cellSaveData.cpp @@ -569,7 +569,7 @@ static NEVER_INLINE error_code savedata_op(ppu_thread& ppu, u32 operation, u32 v const auto lv2_sleep = [](ppu_thread& ppu, usz sleep_time) { lv2_obj::sleep(ppu); - std::this_thread::sleep_for(std::chrono::microseconds(sleep_time)); + lv2_obj::wait_timeout(sleep_time); ppu.check_state(); }; diff --git a/rpcs3/Emu/Cell/lv2/sys_sync.h b/rpcs3/Emu/Cell/lv2/sys_sync.h index 54a7294976..def3624f60 100644 --- a/rpcs3/Emu/Cell/lv2/sys_sync.h +++ b/rpcs3/Emu/Cell/lv2/sys_sync.h @@ -362,6 +362,11 @@ public: } } + if (auto cpu0 = get_current_cpu_thread(); cpu0 && cpu0->is_stopped()) + { + return false; + } + if (thread_ctrl::state() == thread_state::aborting) { return false; diff --git a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp index c92068bed9..79dd7628bd 100644 --- a/rpcs3/Emu/Cell/lv2/sys_usbd.cpp +++ b/rpcs3/Emu/Cell/lv2/sys_usbd.cpp @@ -304,10 +304,7 @@ void usb_handler_thread::operator()() } // If there is no handled devices usb thread is not actively needed - if (handled_devices.empty()) - std::this_thread::sleep_for(500ms); - else - std::this_thread::sleep_for(200us); + thread_ctrl::wait_for(handled_devices.empty() ? 500'000 : 200); } } diff --git a/rpcs3/Emu/NP/np_handler.cpp b/rpcs3/Emu/NP/np_handler.cpp index 06dfaed075..373d1a672d 100644 --- a/rpcs3/Emu/NP/np_handler.cpp +++ b/rpcs3/Emu/NP/np_handler.cpp @@ -664,7 +664,7 @@ void np_handler::operator()() { if (!rpcn.manage_connection()) { - std::this_thread::sleep_for(200ms); + thread_ctrl::wait_for(200'000); continue; } diff --git a/rpcs3/Emu/NP/rpcn_client.cpp b/rpcs3/Emu/NP/rpcn_client.cpp index 879dee7662..c6d5882fc8 100644 --- a/rpcs3/Emu/NP/rpcn_client.cpp +++ b/rpcs3/Emu/NP/rpcn_client.cpp @@ -295,7 +295,7 @@ bool rpcn_client::connect(const std::string& host) connected = true; while (!server_info_received && connected && !is_abort()) - std::this_thread::sleep_for(5ms); + thread_ctrl::wait_for(5000); if (received_version != RPCN_PROTOCOL_VERSION) { @@ -561,7 +561,7 @@ bool rpcn_client::get_reply(const u32 expected_id, std::vector& data) { if (check_for_reply()) return true; - std::this_thread::sleep_for(5ms); + thread_ctrl::wait_for(5000); } if (check_for_reply()) diff --git a/rpcs3/Emu/RSX/Capture/rsx_replay.cpp b/rpcs3/Emu/RSX/Capture/rsx_replay.cpp index 220dd52773..d0a8c59246 100644 --- a/rpcs3/Emu/RSX/Capture/rsx_replay.cpp +++ b/rpcs3/Emu/RSX/Capture/rsx_replay.cpp @@ -190,7 +190,7 @@ namespace rsx for (const auto& replay_cmd : frame->replay_commands) { while (Emu.IsPaused()) - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10'000); if (Emu.IsStopped()) break; @@ -203,7 +203,7 @@ namespace rsx while (!Emu.IsStopped() && !render->is_fifo_idle() && (render->ctrl->get != fifo_stops[stopIdx])) { while (Emu.IsPaused()) - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10'000); std::this_thread::yield(); } @@ -225,7 +225,7 @@ namespace rsx while (!render->is_fifo_idle() && !Emu.IsStopped()) { while (Emu.IsPaused()) - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10'000); } // Check if the captured application used syscall instead of a gcm command to flip @@ -236,7 +236,7 @@ namespace rsx } // random pause to not destroy gpu - std::this_thread::sleep_for(10ms); + thread_ctrl::wait_for(10'000); } get_current_cpu_thread()->state += (cpu_flag::exit + cpu_flag::wait); diff --git a/rpcs3/Emu/RSX/GL/GLPipelineCompiler.cpp b/rpcs3/Emu/RSX/GL/GLPipelineCompiler.cpp index 6120b87269..ff20beb17f 100644 --- a/rpcs3/Emu/RSX/GL/GLPipelineCompiler.cpp +++ b/rpcs3/Emu/RSX/GL/GLPipelineCompiler.cpp @@ -55,7 +55,7 @@ namespace gl job.completion_callback(result); } - m_work_queue.wait(); + thread_ctrl::wait_on(m_work_queue, nullptr); } } diff --git a/rpcs3/Emu/RSX/VK/VKPipelineCompiler.cpp b/rpcs3/Emu/RSX/VK/VKPipelineCompiler.cpp index 4d959193c3..5ec3e10d86 100644 --- a/rpcs3/Emu/RSX/VK/VKPipelineCompiler.cpp +++ b/rpcs3/Emu/RSX/VK/VKPipelineCompiler.cpp @@ -48,7 +48,7 @@ namespace vk } } - m_work_queue.wait(); + thread_ctrl::wait_on(m_work_queue, nullptr); } } diff --git a/rpcs3/Emu/RSX/rsx_cache.h b/rpcs3/Emu/RSX/rsx_cache.h index 1263e573f8..713e0c7ce9 100644 --- a/rpcs3/Emu/RSX/rsx_cache.h +++ b/rpcs3/Emu/RSX/rsx_cache.h @@ -172,7 +172,9 @@ namespace rsx u32 last_update_progress = 0; while ((current_progress < entry_count) && !Emu.IsStopped()) { - std::this_thread::sleep_for(16ms); // Around 60fps should be good enough + thread_ctrl::wait_for(16'000); // Around 60fps should be good enough + + if (Emu.IsStopped()) break; current_progress = std::min(processed.load(), entry_count);