summaryrefslogtreecommitdiffstats
path: root/game/shared/threading.cc
diff options
context:
space:
mode:
authoruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
committeruntodesu <kirill@untode.su>2025-09-11 13:48:31 +0500
commitaaed751bf4430bf4b9b30cef532b8753b9f639ce (patch)
tree16bc751c272ba27ad53ec48dbdd3a6d9e6a8d4c2 /game/shared/threading.cc
parent96bd73ae020ecca1f94698744c77498a89ad19f7 (diff)
downloadvoxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.tar.bz2
voxelius-aaed751bf4430bf4b9b30cef532b8753b9f639ce.zip
Replace most of C strings with string_view
Diffstat (limited to 'game/shared/threading.cc')
-rw-r--r--game/shared/threading.cc22
1 files changed, 18 insertions, 4 deletions
diff --git a/game/shared/threading.cc b/game/shared/threading.cc
index ae3b3ea..209bd3c 100644
--- a/game/shared/threading.cc
+++ b/game/shared/threading.cc
@@ -5,7 +5,7 @@
#include "core/io/cmdline.hh"
#include "core/math/constexpr.hh"
-constexpr static const char* DEFAULT_POOL_SIZE_ARG = "4";
+constexpr static std::string_view DEFAULT_POOL_SIZE_ARG = "4";
static BS::light_thread_pool* thread_pool;
static std::deque<Task*> task_deque;
@@ -38,17 +38,31 @@ void threading::init(void)
auto num_concurrent_threads = std::thread::hardware_concurrency();
unsigned int thread_pool_size;
- if(num_concurrent_threads && !std::strcmp(argument, "max")) {
+ if(num_concurrent_threads && 0 == argument.compare("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 = math::clamp<unsigned int>(std::strtoul(argument, nullptr, 10), 1U, num_concurrent_threads);
+ auto result = std::from_chars(argument.data(), argument.data() + argument.size(), thread_pool_size);
+
+ if(result.ec == std::errc()) {
+ thread_pool_size = math::clamp<unsigned int>(thread_pool_size, 1U, num_concurrent_threads);
+ }
+ else {
+ thread_pool_size = 4U;
+ }
}
else {
- thread_pool_size = math::max<unsigned int>(std::strtoul(argument, nullptr, 10), 1U);
+ auto result = std::from_chars(argument.data(), argument.data() + argument.size(), thread_pool_size);
+
+ if(result.ec == std::errc()) {
+ thread_pool_size = math::max<unsigned int>(thread_pool_size, 1U);
+ }
+ else {
+ thread_pool_size = 4U;
+ }
}
}