diff mbox series

[14/24] configure, meson: move pthread_setname_np checks to Meson

Message ID 20211007130829.632254-9-pbonzini@redhat.com
State New
Headers show
Series configure->meson queue for 6.2 | expand

Commit Message

Paolo Bonzini Oct. 7, 2021, 1:08 p.m. UTC
This makes the pthreads check dead in configure, so remove it
as well.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
 configure                | 78 ----------------------------------------
 meson.build              | 23 ++++++++++++
 util/qemu-thread-posix.c |  5 ++-
 3 files changed, 25 insertions(+), 81 deletions(-)

Comments

Marc-André Lureau Oct. 7, 2021, 8:41 p.m. UTC | #1
On Thu, Oct 7, 2021 at 5:19 PM Paolo Bonzini <pbonzini@redhat.com> wrote:

> This makes the pthreads check dead in configure, so remove it
> as well.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
>

Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com>

(a shame that g_system_thread_set_name() is not exported imho)

---
>  configure                | 78 ----------------------------------------
>  meson.build              | 23 ++++++++++++
>  util/qemu-thread-posix.c |  5 ++-
>  3 files changed, 25 insertions(+), 81 deletions(-)
>
> diff --git a/configure b/configure
> index 52f89b05d6..a1e142d5f8 100755
> --- a/configure
> +++ b/configure
> @@ -3146,71 +3146,6 @@ if test "$modules" = yes; then
>      fi
>  fi
>
> -##########################################
> -# pthread probe
> -PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
> -
> -pthread=no
> -cat > $TMPC << EOF
> -#include <pthread.h>
> -static void *f(void *p) { return NULL; }
> -int main(void) {
> -  pthread_t thread;
> -  pthread_create(&thread, 0, f, 0);
> -  return 0;
> -}
> -EOF
> -if compile_prog "" "" ; then
> -  pthread=yes
> -else
> -  for pthread_lib in $PTHREADLIBS_LIST; do
> -    if compile_prog "" "$pthread_lib" ; then
> -      pthread=yes
> -      break
> -    fi
> -  done
> -fi
> -
> -if test "$mingw32" != yes && test "$pthread" = no; then
> -  error_exit "pthread check failed" \
> -      "Make sure to have the pthread libs and headers installed."
> -fi
> -
> -# check for pthread_setname_np with thread id
> -pthread_setname_np_w_tid=no
> -cat > $TMPC << EOF
> -#include <pthread.h>
> -
> -static void *f(void *p) { return NULL; }
> -int main(void)
> -{
> -    pthread_t thread;
> -    pthread_create(&thread, 0, f, 0);
> -    pthread_setname_np(thread, "QEMU");
> -    return 0;
> -}
> -EOF
> -if compile_prog "" "$pthread_lib" ; then
> -  pthread_setname_np_w_tid=yes
> -fi
> -
> -# check for pthread_setname_np without thread id
> -pthread_setname_np_wo_tid=no
> -cat > $TMPC << EOF
> -#include <pthread.h>
> -
> -static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
> -int main(void)
> -{
> -    pthread_t thread;
> -    pthread_create(&thread, 0, f, 0);
> -    return 0;
> -}
> -EOF
> -if compile_prog "" "$pthread_lib" ; then
> -  pthread_setname_np_wo_tid=yes
> -fi
> -
>  ##########################################
>  # libssh probe
>  if test "$libssh" != "no" ; then
> @@ -4496,19 +4431,6 @@ if test "$debug_mutex" = "yes" ; then
>    echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
>  fi
>
> -# Hold two types of flag:
> -#   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name
> on
> -#                                     a thread we have a handle to
> -#   CONFIG_PTHREAD_SETNAME_NP_W_TID - A way of doing it on a particular
> -#                                     platform
> -if test "$pthread_setname_np_w_tid" = "yes" ; then
> -  echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
> -  echo "CONFIG_PTHREAD_SETNAME_NP_W_TID=y" >> $config_host_mak
> -elif test "$pthread_setname_np_wo_tid" = "yes" ; then
> -  echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
> -  echo "CONFIG_PTHREAD_SETNAME_NP_WO_TID=y" >> $config_host_mak
> -fi
> -
>  if test "$bochs" = "yes" ; then
>    echo "CONFIG_BOCHS=y" >> $config_host_mak
>  fi
> diff --git a/meson.build b/meson.build
> index 935a20c198..54b2afdb96 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -1586,6 +1586,29 @@ config_host_data.set('CONFIG_POSIX_MADVISE',
> cc.links(gnu_source_prefix + '''
>    #include <sys/mman.h>
>    #include <stddef.h>
>    int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED);
> }'''))
> +
> +config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links('''
> +  #include <pthread.h>
> +
> +  static void *f(void *p) { return NULL; }
> +  int main(void)
> +  {
> +    pthread_t thread;
> +    pthread_create(&thread, 0, f, 0);
> +    pthread_setname_np(thread, "QEMU");
> +    return 0;
> +  }''', dependencies: threads))
> +config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links('''
> +  #include <pthread.h>
> +
> +  static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
> +  int main(void)
> +  {
> +    pthread_t thread;
> +    pthread_create(&thread, 0, f, 0);
> +    return 0;
> +  }''', dependencies: threads))
> +
>  config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + '''
>    #include <unistd.h>
>    #include <sys/syscall.h>
> diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
> index 6c5004220d..e1225b63bd 100644
> --- a/util/qemu-thread-posix.c
> +++ b/util/qemu-thread-posix.c
> @@ -23,7 +23,8 @@ void qemu_thread_naming(bool enable)
>  {
>      name_threads = enable;
>
> -#ifndef CONFIG_THREAD_SETNAME_BYTHREAD
> +#if !defined CONFIG_PTHREAD_SETNAME_NP_W_TID && \
> +    !defined CONFIG_PTHREAD_SETNAME_NP_WO_TID
>      /* This is a debugging option, not fatal */
>      if (enable) {
>          fprintf(stderr, "qemu: thread naming not supported on this
> host\n");
> @@ -522,7 +523,6 @@ static void *qemu_thread_start(void *args)
>      void *arg = qemu_thread_args->arg;
>      void *r;
>
> -#ifdef CONFIG_THREAD_SETNAME_BYTHREAD
>      /* Attempt to set the threads name; note that this is for debug, so
>       * we're not going to fail if we can't set it.
>       */
> @@ -533,7 +533,6 @@ static void *qemu_thread_start(void *args)
>          pthread_setname_np(qemu_thread_args->name);
>  # endif
>      }
> -#endif
>      QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name);
>      g_free(qemu_thread_args->name);
>      g_free(qemu_thread_args);
> --
> 2.31.1
>
>
>
>
diff mbox series

Patch

diff --git a/configure b/configure
index 52f89b05d6..a1e142d5f8 100755
--- a/configure
+++ b/configure
@@ -3146,71 +3146,6 @@  if test "$modules" = yes; then
     fi
 fi
 
-##########################################
-# pthread probe
-PTHREADLIBS_LIST="-pthread -lpthread -lpthreadGC2"
-
-pthread=no
-cat > $TMPC << EOF
-#include <pthread.h>
-static void *f(void *p) { return NULL; }
-int main(void) {
-  pthread_t thread;
-  pthread_create(&thread, 0, f, 0);
-  return 0;
-}
-EOF
-if compile_prog "" "" ; then
-  pthread=yes
-else
-  for pthread_lib in $PTHREADLIBS_LIST; do
-    if compile_prog "" "$pthread_lib" ; then
-      pthread=yes
-      break
-    fi
-  done
-fi
-
-if test "$mingw32" != yes && test "$pthread" = no; then
-  error_exit "pthread check failed" \
-      "Make sure to have the pthread libs and headers installed."
-fi
-
-# check for pthread_setname_np with thread id
-pthread_setname_np_w_tid=no
-cat > $TMPC << EOF
-#include <pthread.h>
-
-static void *f(void *p) { return NULL; }
-int main(void)
-{
-    pthread_t thread;
-    pthread_create(&thread, 0, f, 0);
-    pthread_setname_np(thread, "QEMU");
-    return 0;
-}
-EOF
-if compile_prog "" "$pthread_lib" ; then
-  pthread_setname_np_w_tid=yes
-fi
-
-# check for pthread_setname_np without thread id
-pthread_setname_np_wo_tid=no
-cat > $TMPC << EOF
-#include <pthread.h>
-
-static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
-int main(void)
-{
-    pthread_t thread;
-    pthread_create(&thread, 0, f, 0);
-    return 0;
-}
-EOF
-if compile_prog "" "$pthread_lib" ; then
-  pthread_setname_np_wo_tid=yes
-fi
-
 ##########################################
 # libssh probe
 if test "$libssh" != "no" ; then
@@ -4496,19 +4431,6 @@  if test "$debug_mutex" = "yes" ; then
   echo "CONFIG_DEBUG_MUTEX=y" >> $config_host_mak
 fi
 
-# Hold two types of flag:
-#   CONFIG_THREAD_SETNAME_BYTHREAD  - we've got a way of setting the name on
-#                                     a thread we have a handle to
-#   CONFIG_PTHREAD_SETNAME_NP_W_TID - A way of doing it on a particular
-#                                     platform
-if test "$pthread_setname_np_w_tid" = "yes" ; then
-  echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
-  echo "CONFIG_PTHREAD_SETNAME_NP_W_TID=y" >> $config_host_mak
-elif test "$pthread_setname_np_wo_tid" = "yes" ; then
-  echo "CONFIG_THREAD_SETNAME_BYTHREAD=y" >> $config_host_mak
-  echo "CONFIG_PTHREAD_SETNAME_NP_WO_TID=y" >> $config_host_mak
-fi
-
 if test "$bochs" = "yes" ; then
   echo "CONFIG_BOCHS=y" >> $config_host_mak
 fi
diff --git a/meson.build b/meson.build
index 935a20c198..54b2afdb96 100644
--- a/meson.build
+++ b/meson.build
@@ -1586,6 +1586,29 @@  config_host_data.set('CONFIG_POSIX_MADVISE', cc.links(gnu_source_prefix + '''
   #include <sys/mman.h>
   #include <stddef.h>
   int main(void) { return posix_madvise(NULL, 0, POSIX_MADV_DONTNEED); }'''))
+
+config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_W_TID', cc.links('''
+  #include <pthread.h>
+
+  static void *f(void *p) { return NULL; }
+  int main(void)
+  {
+    pthread_t thread;
+    pthread_create(&thread, 0, f, 0);
+    pthread_setname_np(thread, "QEMU");
+    return 0;
+  }''', dependencies: threads))
+config_host_data.set('CONFIG_PTHREAD_SETNAME_NP_WO_TID', cc.links('''
+  #include <pthread.h>
+
+  static void *f(void *p) { pthread_setname_np("QEMU"); return NULL; }
+  int main(void)
+  {
+    pthread_t thread;
+    pthread_create(&thread, 0, f, 0);
+    return 0;
+  }''', dependencies: threads))
+
 config_host_data.set('CONFIG_SIGNALFD', cc.links(gnu_source_prefix + '''
   #include <unistd.h>
   #include <sys/syscall.h>
diff --git a/util/qemu-thread-posix.c b/util/qemu-thread-posix.c
index 6c5004220d..e1225b63bd 100644
--- a/util/qemu-thread-posix.c
+++ b/util/qemu-thread-posix.c
@@ -23,7 +23,8 @@  void qemu_thread_naming(bool enable)
 {
     name_threads = enable;
 
-#ifndef CONFIG_THREAD_SETNAME_BYTHREAD
+#if !defined CONFIG_PTHREAD_SETNAME_NP_W_TID && \
+    !defined CONFIG_PTHREAD_SETNAME_NP_WO_TID
     /* This is a debugging option, not fatal */
     if (enable) {
         fprintf(stderr, "qemu: thread naming not supported on this host\n");
@@ -522,7 +523,6 @@  static void *qemu_thread_start(void *args)
     void *arg = qemu_thread_args->arg;
     void *r;
 
-#ifdef CONFIG_THREAD_SETNAME_BYTHREAD
     /* Attempt to set the threads name; note that this is for debug, so
      * we're not going to fail if we can't set it.
      */
@@ -533,7 +533,6 @@  static void *qemu_thread_start(void *args)
         pthread_setname_np(qemu_thread_args->name);
 # endif
     }
-#endif
     QEMU_TSAN_ANNOTATE_THREAD_NAME(qemu_thread_args->name);
     g_free(qemu_thread_args->name);
     g_free(qemu_thread_args);