Untested libretro fixes, misc

This commit is contained in:
Henrik Rydgård 2021-06-12 23:42:52 +02:00
parent 09ec15e78b
commit 2d6a73792b
3 changed files with 16 additions and 2 deletions

View File

@ -46,6 +46,11 @@ ThreadManager::ThreadManager() : global_(new GlobalThreadContext()) {
}
ThreadManager::~ThreadManager() {
delete global_;
global_ = nullptr;;
}
void ThreadManager::Teardown() {
for (size_t i = 0; i < global_->threads_.size(); i++) {
global_->threads_[i]->cancelled = true;
global_->threads_[i]->cond.notify_one();
@ -55,7 +60,6 @@ ThreadManager::~ThreadManager() {
delete global_->threads_[i];
}
global_->threads_.clear();
delete global_;
}
static void WorkerThreadFunc(GlobalThreadContext *global, ThreadContext *thread) {
@ -95,6 +99,10 @@ static void WorkerThreadFunc(GlobalThreadContext *global, ThreadContext *thread)
}
void ThreadManager::Init(int numRealCores, int numLogicalCores) {
if (!global_->threads_.empty()) {
Teardown();
}
numComputeThreads_ = std::min(numRealCores, MAX_CORES_TO_USE);
int numThreads = numComputeThreads_ + EXTRA_THREADS;
numThreads_ = numThreads;

View File

@ -58,7 +58,9 @@ public:
int GetNumLooperThreads() const;
private:
GlobalThreadContext *global_;
void Teardown();
GlobalThreadContext *global_ = nullptr;
int numThreads_ = 0;
int numComputeThreads_ = 0;

View File

@ -6,6 +6,7 @@
#include <vector>
#include <cstdlib>
#include "Common/CPUDetect.h"
#include "Common/Log.h"
#include "Common/LogManager.h"
#include "Common/System/Display.h"
@ -17,6 +18,7 @@
#include "Common/ConsoleListener.h"
#include "Common/Input/InputState.h"
#include "Common/Thread/ThreadUtil.h"
#include "Common/Thread/ThreadManager.h"
#include "Common/File/VFS/VFS.h"
#include "Common/File/VFS/AssetReader.h"
@ -400,6 +402,8 @@ void retro_init(void)
LogManager::Init(&g_Config.bEnableLogging);
g_threadManager.Init(cpu_info.num_cores, cpu_info.logical_cpu_count);
host = new LibretroHost;
if (environ_cb(RETRO_ENVIRONMENT_GET_LOG_INTERFACE, &log))