mirror of
https://github.com/stenzek/duckstation.git
synced 2025-06-08 04:25:37 +00:00
RegTest: Add function queueing for RunOnCPUThread()
This commit is contained in:
parent
5f48adb53a
commit
f0d4816de7
@ -55,8 +55,19 @@ static bool SetFolders();
|
|||||||
static bool SetNewDataRoot(const std::string& filename);
|
static bool SetNewDataRoot(const std::string& filename);
|
||||||
static void DumpSystemStateHashes();
|
static void DumpSystemStateHashes();
|
||||||
static std::string GetFrameDumpPath(u32 frame);
|
static std::string GetFrameDumpPath(u32 frame);
|
||||||
|
static void ProcessCPUThreadEvents();
|
||||||
static void GPUThreadEntryPoint();
|
static void GPUThreadEntryPoint();
|
||||||
|
|
||||||
|
struct RegTestHostState
|
||||||
|
{
|
||||||
|
ALIGN_TO_CACHE_LINE std::mutex cpu_thread_events_mutex;
|
||||||
|
std::condition_variable cpu_thread_event_done;
|
||||||
|
std::deque<std::pair<std::function<void()>, bool>> cpu_thread_events;
|
||||||
|
u32 blocking_cpu_events_pending = 0;
|
||||||
|
};
|
||||||
|
|
||||||
|
static RegTestHostState s_state;
|
||||||
|
|
||||||
} // namespace RegTestHost
|
} // namespace RegTestHost
|
||||||
|
|
||||||
static std::unique_ptr<MemorySettingsInterface> s_base_settings_interface;
|
static std::unique_ptr<MemorySettingsInterface> s_base_settings_interface;
|
||||||
@ -326,6 +337,8 @@ void Host::OnMediaCaptureStopped()
|
|||||||
|
|
||||||
void Host::PumpMessagesOnCPUThread()
|
void Host::PumpMessagesOnCPUThread()
|
||||||
{
|
{
|
||||||
|
RegTestHost::ProcessCPUThreadEvents();
|
||||||
|
|
||||||
s_frames_remaining--;
|
s_frames_remaining--;
|
||||||
if (s_frames_remaining == 0)
|
if (s_frames_remaining == 0)
|
||||||
{
|
{
|
||||||
@ -336,8 +349,36 @@ void Host::PumpMessagesOnCPUThread()
|
|||||||
|
|
||||||
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
|
void Host::RunOnCPUThread(std::function<void()> function, bool block /* = false */)
|
||||||
{
|
{
|
||||||
// only one thread in this version...
|
using namespace RegTestHost;
|
||||||
function();
|
|
||||||
|
std::unique_lock lock(s_state.cpu_thread_events_mutex);
|
||||||
|
s_state.cpu_thread_events.emplace_back(std::move(function), block);
|
||||||
|
s_state.blocking_cpu_events_pending += BoolToUInt32(block);
|
||||||
|
if (block)
|
||||||
|
s_state.cpu_thread_event_done.wait(lock, []() { return s_state.blocking_cpu_events_pending == 0; });
|
||||||
|
}
|
||||||
|
|
||||||
|
void RegTestHost::ProcessCPUThreadEvents()
|
||||||
|
{
|
||||||
|
std::unique_lock lock(s_state.cpu_thread_events_mutex);
|
||||||
|
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
if (s_state.cpu_thread_events.empty())
|
||||||
|
break;
|
||||||
|
|
||||||
|
auto event = std::move(s_state.cpu_thread_events.front());
|
||||||
|
s_state.cpu_thread_events.pop_front();
|
||||||
|
lock.unlock();
|
||||||
|
event.first();
|
||||||
|
lock.lock();
|
||||||
|
|
||||||
|
if (event.second)
|
||||||
|
{
|
||||||
|
s_state.blocking_cpu_events_pending--;
|
||||||
|
s_state.cpu_thread_event_done.notify_one();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Host::RequestResizeHostDisplay(s32 width, s32 height)
|
void Host::RequestResizeHostDisplay(s32 width, s32 height)
|
||||||
@ -996,6 +1037,7 @@ cleanup:
|
|||||||
s_gpu_thread.Join();
|
s_gpu_thread.Join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RegTestHost::ProcessCPUThreadEvents();
|
||||||
System::CPUThreadShutdown();
|
System::CPUThreadShutdown();
|
||||||
System::ProcessShutdown();
|
System::ProcessShutdown();
|
||||||
return result;
|
return result;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user