frame_dumper: Switch to std::jthread

This commit is contained in:
emufan4568
2022-09-08 23:49:38 +03:00
committed by GPUCode
parent c080ed35c2
commit e22e641736
2 changed files with 9 additions and 16 deletions

View File

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

View File

@ -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<Frontend::GraphicsContext> context;
std::thread present_thread;
std::atomic_bool stop_requested{false};
std::jthread present_thread;
// PBOs used to dump frames faster
std::array<OGLBuffer, 2> pbos;