aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2025-10-10 15:34:40 +0200
committerStefan Boberg <[email protected]>2025-10-10 15:34:40 +0200
commitfc04bb9c9f5c7ea83b36eace264120f907833e2b (patch)
tree9ca5f75ebe89aa914c5163c353273398c1bbd1f4 /src/zencore
parentMerge branch 'sb/zen-master' of ssh://arn-wd-l1704:2222/ue-foundation/zen int... (diff)
parentadded --corelimit option to zenserver (diff)
downloadzen-fc04bb9c9f5c7ea83b36eace264120f907833e2b.tar.xz
zen-fc04bb9c9f5c7ea83b36eace264120f907833e2b.zip
Merge branches 'sb/zen-master' and 'sb/zen-master' of ssh://arn-wd-l1704:2222/ue-foundation/zen into sb/zen-master
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/include/zencore/thread.h6
-rw-r--r--src/zencore/thread.cpp21
2 files changed, 25 insertions, 2 deletions
diff --git a/src/zencore/include/zencore/thread.h b/src/zencore/include/zencore/thread.h
index d9fb5c023..11ef01a35 100644
--- a/src/zencore/include/zencore/thread.h
+++ b/src/zencore/include/zencore/thread.h
@@ -233,8 +233,10 @@ SetAtomicMax(std::atomic_uint64_t& Max, uint64_t Value)
}
}
-ZENCORE_API int GetCurrentThreadId();
-ZENCORE_API void Sleep(int ms);
+void LimitHardwareConcurrency(unsigned int);
+unsigned int GetHardwareConcurrency();
+int GetCurrentThreadId();
+void Sleep(int ms);
void thread_forcelink(); // internal
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