From e22e641736ac47caac14c41ae92aff1c30e48717 Mon Sep 17 00:00:00 2001 From: emufan4568 Date: Thu, 8 Sep 2022 23:49:38 +0300 Subject: [PATCH] frame_dumper: Switch to std::jthread --- .../renderer_opengl/frame_dumper_opengl.cpp | 18 ++++++------------ .../renderer_opengl/frame_dumper_opengl.h | 7 +++---- 2 files changed, 9 insertions(+), 16 deletions(-) diff --git a/src/video_core/renderer_opengl/frame_dumper_opengl.cpp b/src/video_core/renderer_opengl/frame_dumper_opengl.cpp index c7892a5f2..d6958d16b 100644 --- a/src/video_core/renderer_opengl/frame_dumper_opengl.cpp +++ b/src/video_core/renderer_opengl/frame_dumper_opengl.cpp @@ -13,11 +13,6 @@ FrameDumperOpenGL::FrameDumperOpenGL(VideoDumper::Backend& video_dumper_, Frontend::EmuWindow& emu_window) : video_dumper(video_dumper_), context(emu_window.CreateSharedContext()) {} -FrameDumperOpenGL::~FrameDumperOpenGL() { - if (present_thread.joinable()) - present_thread.join(); -} - bool FrameDumperOpenGL::IsDumping() const { return video_dumper.IsDumping(); } @@ -27,22 +22,21 @@ Layout::FramebufferLayout FrameDumperOpenGL::GetLayout() const { } void FrameDumperOpenGL::StartDumping() { - if (present_thread.joinable()) - present_thread.join(); - - present_thread = std::thread(&FrameDumperOpenGL::PresentLoop, this); + present_thread = std::jthread([&](std::stop_token stop_token) { + PresentLoop(stop_token); + }); } void FrameDumperOpenGL::StopDumping() { - stop_requested.store(true, std::memory_order_relaxed); + present_thread.request_stop(); } -void FrameDumperOpenGL::PresentLoop() { +void FrameDumperOpenGL::PresentLoop(std::stop_token stop_token) { const auto scope = context->Acquire(); InitializeOpenGLObjects(); const auto& layout = GetLayout(); - while (!stop_requested.exchange(false)) { + while (!stop_token.stop_requested()) { auto frame = mailbox->TryGetPresentFrame(200); if (!frame) { continue; diff --git a/src/video_core/renderer_opengl/frame_dumper_opengl.h b/src/video_core/renderer_opengl/frame_dumper_opengl.h index da6d96053..e0d02c01b 100644 --- a/src/video_core/renderer_opengl/frame_dumper_opengl.h +++ b/src/video_core/renderer_opengl/frame_dumper_opengl.h @@ -29,7 +29,7 @@ class RendererOpenGL; class FrameDumperOpenGL { public: explicit FrameDumperOpenGL(VideoDumper::Backend& video_dumper, Frontend::EmuWindow& emu_window); - ~FrameDumperOpenGL(); + ~FrameDumperOpenGL() = default; bool IsDumping() const; Layout::FramebufferLayout GetLayout() const; @@ -41,12 +41,11 @@ public: private: void InitializeOpenGLObjects(); void CleanupOpenGLObjects(); - void PresentLoop(); + void PresentLoop(std::stop_token stop_token); VideoDumper::Backend& video_dumper; std::unique_ptr context; - std::thread present_thread; - std::atomic_bool stop_requested{false}; + std::jthread present_thread; // PBOs used to dump frames faster std::array pbos;