move pthread_setaffinity_np check to the build system
authorDylan Baker <dylan@pnwbakers.com>
Thu, 13 Sep 2018 18:06:09 +0000 (11:06 -0700)
committerDylan Baker <dylan@pnwbakers.com>
Mon, 17 Sep 2018 20:16:46 +0000 (13:16 -0700)
Rather than trying to encode all of the rules in a header, lets just put
them in the build system where they belong. This fixes the build on
FreeBSD, which does have pthraed_setaffinity_np, but it's in a
pthread_np.h, not behind _GNU_SOURCE. FreeBSD also implements cpu_set
slightly differently, so additional changes would be required to get it
working right there anyway.

v2: - fix #define in autotools

Fixes: 9f1bbbdbbd77d346c74c7abbb31f399151a85713
       ("util: try to fix the Android and MacOS build")
Cc: Emil Velikov <emil.velikov@collabora.com>
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Reviewed-by: Eric Engestrom <eric.engestrom@intel.com>
configure.ac
meson.build
src/util/u_thread.h

index f8bb131cb6329ff8c193a178df9151513258aa1c..7583a375ad75454215e5dd88d5dc2d59e586a90f 100644 (file)
@@ -968,6 +968,22 @@ if test "x$pthread_stubs_possible" = xyes; then
     PKG_CHECK_MODULES(PTHREADSTUBS, pthread-stubs >= 0.4)
 fi
 
+save_LIBS="$LIBS"
+LIBS="$PTHREAD_LIBS"
+AC_MSG_CHECKING(whether pthread_setaffinity_np is supported)
+AC_LINK_IFELSE([AC_LANG_SOURCE([[
+    #define _GNU_SOURCE
+    #include <pthread.h>
+    int main() {
+       void *a = (void*) &pthread_setaffinity_np;
+       long b = (long) a;
+       return (int) b;
+    }]])],
+  [DEFINES="$DEFINES -DHAVE_PTHREAD_SETAFFINITY"];
+   AC_MSG_RESULT([yes]),
+   AC_MSG_RESULT([no]))
+LIBS="$save_LIBS"
+
 dnl Check for futex for fast inline simple_mtx_t.
 AC_CHECK_HEADER([linux/futex.h], [DEFINES="$DEFINES -DHAVE_LINUX_FUTEX_H"])
 
index 0d534b9b4a9877e21545fa9cb9bafc479f36c9bc..0588ebf8e7a9a18b498df4a4c42686578e32c665 100644 (file)
@@ -1070,6 +1070,13 @@ pre_args += '-DHAVE_ZLIB'
 dep_thread = dependency('threads')
 if dep_thread.found() and host_machine.system() != 'windows'
   pre_args += '-DHAVE_PTHREAD'
+  if cc.has_function(
+      'pthread_setaffinity_np',
+      dependencies : dep_thread,
+      prefix : '#include <pthread.h>',
+      args : '-D_GNU_SOURCE')
+    pre_args += '-DHAVE_PTHREAD_SETAFFINITY'
+  endif
 endif
 if with_amd_vk or with_gallium_radeonsi or with_gallium_r600 or with_gallium_opencl
   dep_elf = dependency('libelf', required : false)
index eee6f3c712d583af5a5883d39f510fae2ed0172e..7538d7d634b20bb007c4f18f930f6b0081fed5e5 100644 (file)
 #include <signal.h>
 #endif
 
-#if defined(HAVE_PTHREAD) && !defined(ANDROID) && !defined(__APPLE__)
-#define HAVE_PTHREAD_SETAFFINITY
-#endif
-
 static inline thrd_t u_thread_create(int (*routine)(void *), void *param)
 {
    thrd_t thread;