1
0
forked from 0ad/0ad

Fixes the default number of workers in TaskManager in case of zero hardware_concurrency.

Differential Revision: https://code.wildfiregames.com/D4768
This was SVN commit r27064.
This commit is contained in:
Vladislav Belov 2022-08-20 20:40:05 +00:00
parent 2285d84d3d
commit d286080285
2 changed files with 24 additions and 5 deletions

View File

@ -53,6 +53,7 @@
#include <sstream>
#include <string>
#include <thread>
static void ReportSDL(const ScriptRequest& rq, JS::HandleValue settings);
static void ReportFreeType(const ScriptRequest& rq, JS::HandleValue settings);
@ -194,8 +195,10 @@ void RunHardwareDetection()
Script::SetProperty(rq, settings, "timer_resolution", timer_Resolution());
Script::SetProperty(rq, settings, "hardware_concurrency", std::thread::hardware_concurrency());
// The version should be increased for every meaningful change.
const int reportVersion = 19;
const int reportVersion = 20;
// Send the same data to the reporting system
g_UserReporter.SubmitReport(
@ -225,6 +228,11 @@ static void ReportSDL(const ScriptRequest& rq, JS::HandleValue settings)
// This is null in atlas (and further the call triggers an assertion).
const char* backend = g_VideoMode.GetWindow() ? GetSDLSubsystem(g_VideoMode.GetWindow()) : "none";
Script::SetProperty(rq, settings, "sdl_video_backend", backend ? backend : "unknown");
Script::SetProperty(rq, settings, "sdl_display_count", SDL_GetNumVideoDisplays());
Script::SetProperty(rq, settings, "sdl_cpu_count", SDL_GetCPUCount());
Script::SetProperty(rq, settings, "sdl_system_ram", SDL_GetSystemRAM());
}
static void ReportFreeType(const ScriptRequest& rq, JS::HandleValue settings)

View File

@ -36,15 +36,26 @@
namespace Threading
{
namespace
{
/**
* Minimum number of TaskManager workers.
*/
static constexpr size_t MIN_THREADS = 3;
constexpr size_t MIN_WORKERS = 3;
/**
* Maximum number of TaskManager workers.
*/
static constexpr size_t MAX_THREADS = 32;
constexpr size_t MAX_WORKERS = 32;
size_t GetDefaultNumberOfWorkers()
{
const size_t hardware_concurrency = std::thread::hardware_concurrency();
return hardware_concurrency ? Clamp(hardware_concurrency - 1, MIN_WORKERS, MAX_WORKERS) : MIN_WORKERS;
}
} // anonymous namespace
std::unique_ptr<TaskManager> g_TaskManager;
@ -155,14 +166,14 @@ protected:
mutable size_t m_RoundRobinIdx = 0;
};
TaskManager::TaskManager() : TaskManager(std::thread::hardware_concurrency() - 1)
TaskManager::TaskManager() : TaskManager(GetDefaultNumberOfWorkers())
{
}
TaskManager::TaskManager(size_t numberOfWorkers)
{
m = std::make_unique<Impl>(*this);
numberOfWorkers = Clamp<size_t>(numberOfWorkers, MIN_THREADS, MAX_THREADS);
numberOfWorkers = Clamp<size_t>(numberOfWorkers, MIN_WORKERS, MAX_WORKERS);
m->SetupWorkers(numberOfWorkers);
}