[runtime] Provide fallback for Linux systems that lack CPU_COUNT in sched.h, fixes...
authorMiguel de Icaza <miguel@gnome.org>
Sat, 3 Dec 2016 02:22:38 +0000 (21:22 -0500)
committerGitHub <noreply@github.com>
Sat, 3 Dec 2016 02:22:38 +0000 (21:22 -0500)
configure.ac
mono/profiler/mono-profiler-log.c
mono/utils/mono-proclib.c

index 0ef5c0d3b4c45257fb35a5da513f8211542fd100..e5b699d038c5a95b7864e92b93f12aecfba64e28 100644 (file)
@@ -1404,7 +1404,15 @@ if test x$host_win32 = xno; then
                # We have the new, three-parameter version
                AC_MSG_RESULT(no)
        ])
-
+       AC_TRY_COMPILE([#include <sched.h>], [
+            CPU_COUNT((void *) 0);
+       ], [
+               AC_MSG_RESULT(yes)
+               AC_DEFINE(GLIBC_HAS_CPU_COUNT, 1, [GLIBC has CPU_COUNT macro in sched.h])
+       ], [
+               # We have the new, three-parameter version
+               AC_MSG_RESULT(no)
+       ])
 
        dnl ******************************************************************
        dnl *** Check for large file support                               ***
index 67741d99d34f14bbf06ca8335ed7a63bc4b23908..b4b2751e34a872615453c3bb2ffa1629d256b534 100644 (file)
 #include <zlib.h>
 #endif
 
+#ifdef HAVE_SCHED_GETAFFINITY
+#  ifndef GLIBC_HAS_CPU_COUNT
+static int
+CPU_COUNT(cpu_set_t *set)
+{
+       int i, count = 0;
+
+       for (int i = 0; i < CPU_SETSIZE; i++)
+               if (CPU_ISSET(i, set))
+                       count++;
+       return count;
+}
+#  endif
+#endif
+
 #define BUFFER_SIZE (4096 * 16)
 
 /* Worst-case size in bytes of a 64-bit value encoded with LEB128. */
index 9c37ccf2ec11874e121c4a394e980461c8a3c9f3..f1a28444425eadb87c55a6626e1f70d173458e8f 100644 (file)
 #define USE_SYSCTL 1
 #endif
 
+#ifdef HAVE_SCHED_GETAFFINITY
+#  ifndef GLIBC_HAS_CPU_COUNT
+static int
+CPU_COUNT(cpu_set_t *set)
+{
+       int i, count = 0;
+
+       for (int i = 0; i < CPU_SETSIZE; i++)
+               if (CPU_ISSET(i, set))
+                       count++;
+       return count;
+}
+#  endif
+#endif
+
 /**
  * mono_process_list:
  * @size: a pointer to a location where the size of the returned array is stored