diff options
| author | untodesu <kirill@untode.su> | 2025-03-16 12:24:03 +0500 |
|---|---|---|
| committer | untodesu <kirill@untode.su> | 2025-03-16 12:24:03 +0500 |
| commit | 933ed978a21d5ffefc376d66f0dc9f5354292ca7 (patch) | |
| tree | a3b87b83219eb6b2dae3f68b3555bb533d715111 /game/shared/threading.cc | |
| parent | c74abc45390a4125e644d2788eefb681cf9f32c4 (diff) | |
| download | voxelius-933ed978a21d5ffefc376d66f0dc9f5354292ca7.tar.bz2 voxelius-933ed978a21d5ffefc376d66f0dc9f5354292ca7.zip | |
Update threading command line arguments
Diffstat (limited to 'game/shared/threading.cc')
| -rw-r--r-- | game/shared/threading.cc | 24 |
1 files changed, 21 insertions, 3 deletions
diff --git a/game/shared/threading.cc b/game/shared/threading.cc index 06a9411..7e6f652 100644 --- a/game/shared/threading.cc +++ b/game/shared/threading.cc @@ -4,6 +4,8 @@ #include "core/cmdline.hh" #include "core/constexpr.hh" +constexpr static const char *DEFAULT_POOL_SIZE_ARG = "4"; + static BS::light_thread_pool *thread_pool; static std::deque<Task *> task_deque; @@ -31,9 +33,25 @@ void Task::set_status(task_status status) void threading::init(void) { - auto threads_arg = cmdline::get("threads", "4"); - auto threads_num = cxpr::clamp<unsigned long>(std::strtoul(threads_arg, nullptr, 10), 2U, 4U); - thread_pool = new BS::light_thread_pool(threads_num); + auto argument = cmdline::get("threads", DEFAULT_POOL_SIZE_ARG); + auto num_concurrent_threads = std::thread::hardware_concurrency(); + unsigned int thread_pool_size; + + if(num_concurrent_threads && !std::strcmp(argument, "max")) { + // Use the maximum available number of concurrent + // hardware threads provided by the implementation + thread_pool_size = num_concurrent_threads; + } + else { + if(num_concurrent_threads) + thread_pool_size = cxpr::clamp<unsigned int>(std::strtoul(argument, nullptr, 10), 1U, num_concurrent_threads); + else thread_pool_size = cxpr::max<unsigned int>(std::strtoul(argument, nullptr, 10), 1U); + } + + spdlog::info("threading: using {} threads for pooling tasks", thread_pool_size); + + thread_pool = new BS::light_thread_pool(thread_pool_size); + task_deque.clear(); } |
