From 02a24cdb7d072249cf023fcd66622fcafa3e6bbf Mon Sep 17 00:00:00 2001 From: Stuart Kenny Date: Thu, 8 Jul 2021 08:34:48 +0100 Subject: [PATCH] Fix black screen on multiple libretro content loads. Moves ThreadPool teardown to retro_unload_game. Gives ThreadPool threads some breathing room to terminate before game load starts spamming it with tasks. --- Common/Thread/ThreadManager.cpp | 4 ---- Common/Thread/ThreadManager.h | 3 +-- libretro/libretro.cpp | 2 ++ 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/Common/Thread/ThreadManager.cpp b/Common/Thread/ThreadManager.cpp index 8ac9ac0a22..4647713ccd 100644 --- a/Common/Thread/ThreadManager.cpp +++ b/Common/Thread/ThreadManager.cpp @@ -98,10 +98,6 @@ static void WorkerThreadFunc(GlobalThreadContext *global, ThreadContext *thread) } void ThreadManager::Init(int numRealCores, int numLogicalCoresPerCpu) { - if (!global_->threads_.empty()) { - Teardown(); - } - numComputeThreads_ = std::min(numRealCores * numLogicalCoresPerCpu, MAX_CORES_TO_USE); int numThreads = numComputeThreads_ + EXTRA_THREADS; numThreads_ = numThreads; diff --git a/Common/Thread/ThreadManager.h b/Common/Thread/ThreadManager.h index b36f8ed26f..822997d921 100644 --- a/Common/Thread/ThreadManager.h +++ b/Common/Thread/ThreadManager.h @@ -46,6 +46,7 @@ public: void Init(int numCores, int numLogicalCoresPerCpu); void EnqueueTask(Task *task, TaskType taskType); void EnqueueTaskOnThread(int threadNum, Task *task, TaskType taskType); + void Teardown(); // Currently does nothing. It will always be best-effort - maybe it cancels, // maybe it doesn't. Note that the id is the id() returned by the task. You need to make that @@ -57,8 +58,6 @@ public: int GetNumLooperThreads() const; private: - void Teardown(); - GlobalThreadContext *global_ = nullptr; int numThreads_ = 0; diff --git a/libretro/libretro.cpp b/libretro/libretro.cpp index cf8be3959e..c5f6f9a0fc 100644 --- a/libretro/libretro.cpp +++ b/libretro/libretro.cpp @@ -675,6 +675,8 @@ void retro_unload_game(void) delete ctx; ctx = nullptr; PSP_CoreParameter().graphicsContext = nullptr; + + g_threadManager.Teardown(); } void retro_reset(void)