summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2023-06-05 14:48:09 -0700
committerVito Caputo <vcaputo@pengaru.com>2023-06-05 14:48:09 -0700
commit2dc2abb1d213012336c21e91bea350a64ba48cda (patch)
treeae61f9c602ed3d2aad5f3c139047a0df9765c13f /src
parent8de13085a61b1b82ed0df31c246b528c328b6d35 (diff)
til_util: actually enforce TIL_MAXCPUS uniformly
The win32 and mach builds were free to violate this, as it's always just been a local define for putting some kind of bound on the linux "/sys/devices/system/cpu/cpuN" probing loop. But in preparation for moving TIL_MAXCPUS out to til_util.h for public consumption in sizing per-cpu arrays, it needs to actually be enforced consistently as an upper bound cap. That way everything can safely assume n_cpus won't ever exceed TIL_MAXCPUS.
Diffstat (limited to 'src')
-rw-r--r--src/til_util.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/til_util.c b/src/til_util.c
index dd2fca2..e91f9d6 100644
--- a/src/til_util.c
+++ b/src/til_util.c
@@ -15,7 +15,7 @@
#include "til_util.h"
#define TIL_SYSFS_CPU "/sys/devices/system/cpu/cpu"
-#define TIL_MAXCPUS 1024
+#define TIL_MAXCPUS 1024
unsigned til_get_ncpus(void)
{
@@ -24,7 +24,7 @@ unsigned til_get_ncpus(void)
GetSystemInfo(&sysinfo);
- return sysinfo.dwNumberOfProcessors;
+ return MIN(sysinfo.dwNumberOfProcessors, TIL_MAXCPUS);
#endif
#ifdef __MACH__
@@ -34,7 +34,7 @@ unsigned til_get_ncpus(void)
if (sysctlbyname("hw.logicalcpu_max", &count, &count_len, NULL, 0) < 0)
return 1;
- return count;
+ return MIN(count, TIL_MAXCPUS);
#else
char path[cstrlen(TIL_SYSFS_CPU "1024") + 1];
unsigned n;
© All Rights Reserved