Fix most of "[x] thread is too sleepy" at Emu.Stop() (#9813)

* Fixes some thread sleep/wait calls
This commit is contained in:
Eladash 2021-02-21 15:43:02 +02:00 committed by GitHub
parent a47bda026b
commit eb0d006168
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 17 deletions

View File

@ -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())

View File

@ -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<rsx::overlays::display_manager>())

View File

@ -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();
};

View File

@ -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;

View File

@ -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);
}
}

View File

@ -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;
}

View File

@ -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<u8>& data)
{
if (check_for_reply())
return true;
std::this_thread::sleep_for(5ms);
thread_ctrl::wait_for(5000);
}
if (check_for_reply())

View File

@ -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);

View File

@ -55,7 +55,7 @@ namespace gl
job.completion_callback(result);
}
m_work_queue.wait();
thread_ctrl::wait_on(m_work_queue, nullptr);
}
}

View File

@ -48,7 +48,7 @@ namespace vk
}
}
m_work_queue.wait();
thread_ctrl::wait_on(m_work_queue, nullptr);
}
}

View File

@ -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);