summaryrefslogtreecommitdiff
path: root/src/til_util.c
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2021-10-01 16:35:08 -0700
committerVito Caputo <vcaputo@pengaru.com>2021-10-01 16:35:08 -0700
commitb686b405c6a22b26e9b8082c92ed91513608bea3 (patch)
tree0000f671501863a8ee9b536ba869221d0f6710f9 /src/til_util.c
parentd1da5500261e96efe0ede06fbebb32f0e191f3c1 (diff)
*: librototiller->libtil
Largely mechanical rename of librototiller -> libtil, but introducing a til_ prefix to all librototiller (now libtil) functions and types where a rototiller prefix was absent. This is just a step towards a more libized librototiller, and til is just a nicer to type/read prefix than rototiller_.
Diffstat (limited to 'src/til_util.c')
-rw-r--r--src/til_util.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/til_util.c b/src/til_util.c
new file mode 100644
index 0000000..e9b1021
--- /dev/null
+++ b/src/til_util.c
@@ -0,0 +1,35 @@
+#include <limits.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+#ifdef __WIN32__
+#include <windows.h>
+#endif
+
+#include "til_util.h"
+
+#define TIL_SYSFS_CPU "/sys/devices/system/cpu/cpu"
+#define TIL_MAXCPUS 1024
+
+unsigned til_get_ncpus(void)
+{
+#ifdef __WIN32__
+ SYSTEM_INFO sysinfo;
+
+ GetSystemInfo(&sysinfo);
+
+ return sysinfo.dwNumberOfProcessors;
+#else
+ char path[cstrlen(TIL_SYSFS_CPU "1024") + 1];
+ unsigned n;
+
+ for (n = 0; n < TIL_MAXCPUS; n++) {
+ snprintf(path, sizeof(path), "%s%u", TIL_SYSFS_CPU, n);
+ if (access(path, F_OK) == -1)
+ break;
+ }
+
+ return n == 0 ? 1 : n;
+#endif
+}
© All Rights Reserved