aboutsummaryrefslogtreecommitdiff
path: root/src/zencore/thread.cpp
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-10 15:34:30 +0200
committerStefan Boberg <[email protected]>2025-10-10 15:34:30 +0200
commit07e2df59856ef71bcac54d47c9d4d35b6f9ba7cd (patch)
tree53b8f7e17e1f57af409e703f0a2ffcb7f90378ab /src/zencore/thread.cpp
parentmade server count dynamic via `--count` argument (diff)
downloadzen-07e2df59856ef71bcac54d47c9d4d35b6f9ba7cd.tar.xz
zen-07e2df59856ef71bcac54d47c9d4d35b6f9ba7cd.zip
added --corelimit option to zenserver
Diffstat (limited to 'src/zencore/thread.cpp')
-rw-r--r--src/zencore/thread.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/zencore/thread.cpp b/src/zencore/thread.cpp
index abf282467..7bd21a229 100644
--- a/src/zencore/thread.cpp
+++ b/src/zencore/thread.cpp
@@ -45,6 +45,27 @@ ZEN_THIRD_PARTY_INCLUDES_END
namespace zen {
+static unsigned int LimitConcurrency = 0;
+
+void
+LimitHardwareConcurrency(unsigned int Limit)
+{
+ LimitConcurrency = Limit;
+}
+
+unsigned int
+GetHardwareConcurrency()
+{
+ static unsigned int SysLimit = std::thread::hardware_concurrency();
+
+ if (LimitConcurrency)
+ {
+ return Min(SysLimit, LimitConcurrency);
+ }
+
+ return SysLimit;
+}
+
#if ZEN_PLATFORM_WINDOWS
// The information on how to set the thread name comes from
// a MSDN article: http://msdn2.microsoft.com/en-us/library/xcb2z8hs.aspx