From c17938f96ba9a3f2571387b21328743db8050250 Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Mon, 3 Jan 2022 20:31:51 -0500 Subject: [PATCH] gpu: Add shut down method to synchronize threads before destruction --- src/core/core.cpp | 2 ++ src/video_core/gpu.cpp | 10 ++++++++++ src/video_core/gpu.h | 3 +++ 3 files changed, 15 insertions(+) diff --git a/src/core/core.cpp b/src/core/core.cpp index aa96f709b5..3f9a7f44bc 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -317,6 +317,8 @@ struct System::Impl { is_powered_on = false; exit_lock = false; + gpu_core->NotifyShutdown(); + services.reset(); service_manager.reset(); cheat_engine.reset(); diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 8788f5148f..44fda27ef9 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -312,6 +312,12 @@ struct GPU::Impl { cpu_context->MakeCurrent(); } + void NotifyShutdown() { + std::unique_lock lk{sync_mutex}; + shutting_down.store(true, std::memory_order::relaxed); + sync_cv.notify_all(); + } + /// Obtain the CPU Context void ObtainContext() { cpu_context->MakeCurrent(); @@ -859,6 +865,10 @@ void GPU::Start() { impl->Start(); } +void GPU::NotifyShutdown() { + impl->NotifyShutdown(); +} + void GPU::ObtainContext() { impl->ObtainContext(); } diff --git a/src/video_core/gpu.h b/src/video_core/gpu.h index 500411176f..3188b83edf 100644 --- a/src/video_core/gpu.h +++ b/src/video_core/gpu.h @@ -232,6 +232,9 @@ public: /// core timing events. void Start(); + /// Performs any additional necessary steps to shutdown GPU emulation. + void NotifyShutdown(); + /// Obtain the CPU Context void ObtainContext();