From f05bc50d40cded130e188d165e6b310f2a72d58f Mon Sep 17 00:00:00 2001 From: RSDuck Date: Thu, 11 Feb 2021 16:00:36 +0100 Subject: [PATCH] use std::function in Thread_Create so we can revert back to using it --- src/GPU3D_Soft.cpp | 9 +++------ src/GPU3D_Soft.h | 3 +-- src/Platform.h | 4 +++- src/frontend/qt_sdl/Platform.cpp | 2 +- 4 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp index f6d27a0d..de66b6b0 100644 --- a/src/GPU3D_Soft.cpp +++ b/src/GPU3D_Soft.cpp @@ -37,10 +37,8 @@ void SoftRenderer::StopRenderThread() { RenderThreadRunning = false; Platform::Semaphore_Post(Sema_RenderStart); - // Platform::Thread_Wait(RenderThread); - // Platform::Thread_Free(RenderThread); - RenderThread.join(); - + Platform::Thread_Wait(RenderThread); + Platform::Thread_Free(RenderThread); } } @@ -51,8 +49,7 @@ void SoftRenderer::SetupRenderThread() if (!RenderThreadRunning) { RenderThreadRunning = true; - //RenderThread = Platform::Thread_Create(RenderThreadFunc); - RenderThread = std::thread(&SoftRenderer::RenderThreadFunc, this); + RenderThread = Platform::Thread_Create(std::bind(&RenderThreadFunc, this)); } // otherwise more than one frame can be queued up at once diff --git a/src/GPU3D_Soft.h b/src/GPU3D_Soft.h index 851b7c19..ee1977d3 100644 --- a/src/GPU3D_Soft.h +++ b/src/GPU3D_Soft.h @@ -505,8 +505,7 @@ private: // threading bool Threaded; - // Platform::Thread* RenderThread; - std::thread RenderThread; + Platform::Thread* RenderThread; bool RenderThreadRunning; bool RenderThreadRendering; Platform::Semaphore* Sema_RenderStart; diff --git a/src/Platform.h b/src/Platform.h index 42e1e246..9542233a 100644 --- a/src/Platform.h +++ b/src/Platform.h @@ -21,6 +21,8 @@ #include "types.h" +#include + namespace Platform { @@ -68,7 +70,7 @@ inline bool LocalFileExists(const char* name) } struct Thread; -Thread* Thread_Create(void (*func)()); +Thread* Thread_Create(std::function func); void Thread_Free(Thread* thread); void Thread_Wait(Thread* thread); diff --git a/src/frontend/qt_sdl/Platform.cpp b/src/frontend/qt_sdl/Platform.cpp index 7c4b5537..64013058 100644 --- a/src/frontend/qt_sdl/Platform.cpp +++ b/src/frontend/qt_sdl/Platform.cpp @@ -188,7 +188,7 @@ FILE* OpenLocalFile(const char* path, const char* mode) return OpenFile(fullpath.toUtf8(), mode, mode[0] != 'w'); } -Thread* Thread_Create(void (* func)()) +Thread* Thread_Create(std::function func) { QThread* t = QThread::create(func); t->start();