From d866916f42c3bbb21aa6f046140737690c1ce47f Mon Sep 17 00:00:00 2001 From: ameerj <52414509+ameerj@users.noreply.github.com> Date: Mon, 3 Jan 2022 12:31:33 -0500 Subject: gpu: Use std::stop_token in WaitFence for VSync thread Fixes a hang that may occur when stopping emulation and the VSync thread is blocked on the syncpoint condition variable. --- src/video_core/gpu.cpp | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/video_core/gpu.cpp') diff --git a/src/video_core/gpu.cpp b/src/video_core/gpu.cpp index 8788f5148..d98874150 100644 --- a/src/video_core/gpu.cpp +++ b/src/video_core/gpu.cpp @@ -206,7 +206,7 @@ struct GPU::Impl { } /// Allows the CPU/NvFlinger to wait on the GPU before presenting a frame. - void WaitFence(u32 syncpoint_id, u32 value) { + void WaitFence(u32 syncpoint_id, u32 value, std::stop_token stop_token = {}) { // Synced GPU, is always in sync if (!is_async) { return; @@ -218,13 +218,8 @@ struct GPU::Impl { } MICROPROFILE_SCOPE(GPU_wait); std::unique_lock lock{sync_mutex}; - sync_cv.wait(lock, [=, this] { - if (shutting_down.load(std::memory_order_relaxed)) { - // We're shutting down, ensure no threads continue to wait for the next syncpoint - return true; - } - return syncpoints.at(syncpoint_id).load() >= value; - }); + sync_cv.wait(lock, stop_token, + [=, this] { return syncpoints.at(syncpoint_id).load() >= value; }); } void IncrementSyncPoint(u32 syncpoint_id) { @@ -670,8 +665,6 @@ struct GPU::Impl { std::unique_ptr kepler_memory; /// Shader build notifier std::unique_ptr shader_notify; - /// When true, we are about to shut down emulation session, so terminate outstanding tasks - std::atomic_bool shutting_down{}; std::array, Service::Nvidia::MaxSyncPoints> syncpoints{}; @@ -680,7 +673,7 @@ struct GPU::Impl { std::mutex sync_mutex; std::mutex device_mutex; - std::condition_variable sync_cv; + std::condition_variable_any sync_cv; struct FlushRequest { explicit FlushRequest(u64 fence_, VAddr addr_, std::size_t size_) @@ -819,8 +812,8 @@ const VideoCore::ShaderNotify& GPU::ShaderNotify() const { return impl->ShaderNotify(); } -void GPU::WaitFence(u32 syncpoint_id, u32 value) { - impl->WaitFence(syncpoint_id, value); +void GPU::WaitFence(u32 syncpoint_id, u32 value, std::stop_token stop_token) { + impl->WaitFence(syncpoint_id, value, stop_token); } void GPU::IncrementSyncPoint(u32 syncpoint_id) { -- cgit v1.2.3