blob: 9aaa6e62bd0249379c7f1e8bb25e42f0405118dd (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
--- libraries/libobjs/get_nprocs.c.orig 2021-04-22 19:18:04 UTC
+++ libraries/libobjs/get_nprocs.c
@@ -39,10 +39,28 @@
#ifndef HAVE_GET_NPROCS
+#if defined(__FreeBSD__)
+#include <sys/types.h>
+#include <sys/sysctl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#endif
+
/* GNU libc */
int
get_nprocs(void)
{
+#if defined(__FreeBSD__)
+ static int name[2] = {CTL_HW, HW_NCPU};
+ int32_t ncpu;
+ size_t size = sizeof(ncpu);
+ if (sysctl(name, sizeof(name)/sizeof(*name), &ncpu, &size, NULL, 0)) {
+ perror("unable to determine number of CPUs");
+ abort();
+ }
+ return (int)ncpu;
+
+#else
#warning "pippero!!!"
#if defined(_SC_NPROCESSORS_ONLN)
/* POSIX.1. */
@@ -65,6 +83,7 @@ get_nprocs(void)
#endif
/* we assume that there is at least one :) */
return 1;
+#endif
}
#endif /* HAVE_GET_NPROCS */
|