diff --git a/Common/Common.vcxproj b/Common/Common.vcxproj index c0e267176d..c3c58e9b26 100644 --- a/Common/Common.vcxproj +++ b/Common/Common.vcxproj @@ -191,6 +191,7 @@ + @@ -226,6 +227,7 @@ + diff --git a/Common/Common.vcxproj.filters b/Common/Common.vcxproj.filters index 395566ba23..24ebfe6ebd 100644 --- a/Common/Common.vcxproj.filters +++ b/Common/Common.vcxproj.filters @@ -42,6 +42,7 @@ + @@ -68,6 +69,7 @@ + diff --git a/Common/ThreadPool.cpp b/Common/ThreadPool.cpp new file mode 100644 index 0000000000..d98e6628f8 --- /dev/null +++ b/Common/ThreadPool.cpp @@ -0,0 +1,19 @@ +#include "ThreadPool.h" + +#include "../Core/Config.h" + +std::shared_ptr GlobalThreadPool::pool; +bool GlobalThreadPool::initialized = false; + +void GlobalThreadPool::Loop(const std::function& loop, int lower, int upper) { + Inititialize(); + pool->ParallelLoop(loop, lower, upper); +} + +void GlobalThreadPool::Inititialize() { + if(!initialized) { + pool = std::make_shared(g_Config.iNumWorkerThreads); + initialized = true; + } +} + diff --git a/Common/ThreadPool.h b/Common/ThreadPool.h new file mode 100644 index 0000000000..c956b33664 --- /dev/null +++ b/Common/ThreadPool.h @@ -0,0 +1,15 @@ +#pragma once + +#include "../native/thread/threadpool.h" + +class GlobalThreadPool { +public: + // will execute slices of "loop" from "lower" to "upper" + // in parallel on the global thread pool + static void Loop(const std::function& loop, int lower, int upper); + +private: + static std::shared_ptr pool; + static bool initialized; + static void Inititialize(); +}; diff --git a/Core/Config.cpp b/Core/Config.cpp index b38dcfd3c9..266dad3d39 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -20,6 +20,7 @@ #include "Config.h" #include "file/ini_file.h" #include "HLE/sceUtility.h" +#include "Common/CPUDetect.h" Config g_Config; @@ -61,6 +62,7 @@ void Config::Load(const char *iniFileName) general->Get("CurrentDirectory", ¤tDirectory, ""); general->Get("ShowDebuggerOnLoad", &bShowDebuggerOnLoad, false); general->Get("Language", &languageIni, "en_US"); + general->Get("NumWorkerThreads", &iNumWorkerThreads, cpu_info.num_cores); // "default" means let emulator decide, "" means disable. general->Get("ReportHost", &sReportHost, "default"); @@ -172,6 +174,7 @@ void Config::Save() general->Set("WindowY", iWindowY); general->Set("AutoSaveSymbolMap", bAutoSaveSymbolMap); general->Set("Language", languageIni); + general->Set("NumWorkerThreads", iNumWorkerThreads); IniFile::Section *cpu = iniFile.GetOrCreateSection("CPU"); cpu->Set("Jit", bJit); diff --git a/Core/Config.h b/Core/Config.h index 8b6aec96ca..bb134edb3a 100644 --- a/Core/Config.h +++ b/Core/Config.h @@ -40,6 +40,9 @@ public: bool bAutoRun; // start immediately bool bBrowse; + // General + int iNumWorkerThreads; + // Core bool bIgnoreBadMemAccess; bool bFastMemory; diff --git a/ext/xbrz/xbrz.h b/ext/xbrz/xbrz.h index 54b688f442..d54333da4c 100644 --- a/ext/xbrz/xbrz.h +++ b/ext/xbrz/xbrz.h @@ -25,13 +25,6 @@ #include #include "config.h" -#ifdef max -#undef max -#endif -#ifdef min -#undef min -#endif - namespace xbrz { /*