gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r37686 - in libmicrohttpd: . src/microhttpd


From: gnunet
Subject: [GNUnet-SVN] r37686 - in libmicrohttpd: . src/microhttpd
Date: Wed, 10 Aug 2016 15:52:44 +0200

Author: Karlson2k
Date: 2016-08-10 15:52:43 +0200 (Wed, 10 Aug 2016)
New Revision: 37686

Modified:
   libmicrohttpd/configure.ac
   libmicrohttpd/src/microhttpd/mhd_threads.c
   libmicrohttpd/src/microhttpd/mhd_threads.h
Log:
Added support for thread names on FreeBSD, NetBSD, OpenBSD, Darwin, OSF1 and 
others.

Modified: libmicrohttpd/configure.ac
===================================================================
--- libmicrohttpd/configure.ac  2016-08-10 13:52:38 UTC (rev 37685)
+++ libmicrohttpd/configure.ac  2016-08-10 13:52:43 UTC (rev 37686)
@@ -302,7 +302,67 @@
 AM_CONDITIONAL([USE_W32_THREADS], [test "x$USE_THREADS" = "xw32"])
 AC_MSG_RESULT([[$USE_THREADS]])
 
+if test "x$HAVE_POSIX_THREADS" = "xyes"; then
+  # Check for pthread_setname_np()
+  SAVE_LIBS="$LIBS"
+  SAVE_CFLAGS="$CFLAGS"
+  LIBS="$PTHREAD_LIBS $LIBS"
+  CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
+  AC_CHECK_HEADERS([pthread_np.h])
 
+  AC_MSG_CHECKING([[for pthread_setname_np(3) in NetBSD or OSF1 form]])
+  AC_LINK_IFELSE(
+    [AC_LANG_PROGRAM([[
+#include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+]], [[int res = pthread_setname_np(pthread_self(), "name", 0);]])],
+    [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_NETBSD]], [[1]], [Define if you have 
NetBSD form (or OSF1 form) of pthread_setname_np(3) function.])
+     AC_MSG_RESULT([[yes]])],
+    [AC_MSG_RESULT([[no]])
+
+     AC_MSG_CHECKING([[for pthread_setname_np(3) in GNU/Linux form]])
+     AC_LINK_IFELSE(
+       [AC_LANG_PROGRAM([[
+#include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+]], [[int res = pthread_setname_np(pthread_self(), "name");]])],
+        [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_GNU]], [[1]], [Define if you have 
GNU/Linux form of pthread_setname_np(3) function.])
+         AC_MSG_RESULT([[yes]])],
+        [AC_MSG_RESULT([[no]])
+
+         AC_MSG_CHECKING([[for pthread_setname_np(3) in Darwin form]])
+         AC_LINK_IFELSE(
+           [AC_LANG_PROGRAM([[
+#include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+]], [[int res = pthread_setname_np("name");]])],
+           [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP_DARWIN]], [[1]], [Define if 
you have Darwin form of pthread_setname_np(3) function.])
+            AC_MSG_RESULT([[yes]])],
+           [AC_MSG_RESULT([[no]])
+
+            AC_MSG_CHECKING([[for pthread_setname_np(3) in FreeBSD form]])
+            AC_LINK_IFELSE(
+              [AC_LANG_PROGRAM([[
+#include <pthread.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif
+]], [[pthread_set_name_np(pthread_self(), "name");]])],
+              [AC_DEFINE([[HAVE_PTHREAD_SET_NAME_NP_FREEBSD]], [[1]], [Define 
if you have FreeBSD form of pthread_set_name_np(3) function.])
+               AC_MSG_RESULT([[yes]])],
+              [AC_MSG_RESULT([[no]])] ) ]) ]) ])
+
+  LIBS="$SAVE_LIBS"
+  CFLAGS="$SAVE_CFLAGS"
+fi
+
+
 AM_CONDITIONAL(HAVE_W32, [test "x$os_is_native_w32" = "xyes"])
 w32_shared_lib_exp=no
 if test "x$enable_shared" = "xyes" && test "x$os_is_native_w32" = "xyes"; then
@@ -405,22 +465,6 @@
     AC_DEFINE([[HAVE_EPOLL_CREATE1]], [[1]], [Define if you have epoll_create1 
function.])])
 fi
 
-if test "x$HAVE_POSIX_THREADS" = "xyes"; then
-  # Check for pthread_setname_np()
-  SAVE_LIBS="$LIBS"
-  SAVE_CFLAGS="$CFLAGS"
-  LIBS="$PTHREAD_LIBS $LIBS"
-  CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
-  AC_MSG_CHECKING([[for pthread_setname_np]])
-  AC_LINK_IFELSE(
-    [AC_LANG_PROGRAM([[#include <pthread.h>]], [[  
pthread_setname_np(pthread_self(), "name")]])],
-    [AC_DEFINE([[HAVE_PTHREAD_SETNAME_NP]], [[1]], [Define if you have 
pthread_setname_np function.])
-     AC_MSG_RESULT([[yes]])],
-    [AC_MSG_RESULT([[no]])] )
-  LIBS="$SAVE_LIBS"
-  CFLAGS="$SAVE_CFLAGS"
-fi
-
 # Check for headers that are ALWAYS required
 AC_CHECK_HEADERS([fcntl.h math.h errno.h limits.h stdio.h locale.h sys/stat.h 
sys/types.h],,AC_MSG_ERROR([Compiling libmicrohttpd requires standard UNIX 
headers files]))
 

Modified: libmicrohttpd/src/microhttpd/mhd_threads.c
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_threads.c  2016-08-10 13:52:38 UTC (rev 
37685)
+++ libmicrohttpd/src/microhttpd/mhd_threads.c  2016-08-10 13:52:43 UTC (rev 
37686)
@@ -31,6 +31,9 @@
 #endif
 #ifdef MHD_USE_THREAD_NAME_
 #include <stdlib.h>
+#ifdef HAVE_PTHREAD_NP_H
+#include <pthread_np.h>
+#endif /* HAVE_PTHREAD_NP_H */
 #endif /* MHD_USE_THREAD_NAME_ */
 #include <errno.h>
 
@@ -51,7 +54,8 @@
 #else  /* MHD_USE_THREAD_NAME_ */
 
 #if defined(MHD_USE_POSIX_THREADS)
-#ifdef HAVE_PTHREAD_SETNAME_NP
+#if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || 
defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
+    || defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
 /**
  * Set thread name
  * @param thread_id ID of thread
@@ -63,9 +67,23 @@
   if (NULL == thread_name)
     return 0;
 
+#if defined(HAVE_PTHREAD_SETNAME_NP_GNU)
   return !pthread_setname_np (thread_id, thread_name);
+#elif defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD)
+  /* FreeBSD and OpenBSD use different name and void return type */
+  pthread_set_name_np (thread_id, thread_name);
+  return !0;
+#elif defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
+  /* NetBSD use 3 arguments: second argument is string in printf-like format,
+   *                         third argument is single argument for printf;
+   * OSF1 use 3 arguments too, but last one always must be zero (NULL).
+   * MHD doesn't use '%' in thread names, so both form are used in same way.
+   */
+  return !pthread_setname_np (thread_id, thread_name, 0);
+#endif /* HAVE_PTHREAD_SETNAME_NP_NETBSD */
 }
 
+
 /**
  * Set current thread name
  * @param n name to set
@@ -72,8 +90,16 @@
  * @return non-zero on success, zero otherwise
  */
 #define MHD_set_cur_thread_name_(n) MHD_set_thread_name_(pthread_self(),(n))
-#endif /* HAVE_PTHREAD_SETNAME_NP */
+#elif defined(HAVE_PTHREAD_SETNAME_NP_DARWIN)
 
+/**
+ * Set current thread name
+ * @param n name to set
+ * @return non-zero on success, zero otherwise
+ */
+#define MHD_set_cur_thread_name_(n) (!(pthread_setname_np((n))))
+#endif /* HAVE_PTHREAD_SETNAME_NP_DARWIN */
+
 #elif defined(MHD_USE_W32_THREADS)
 #ifndef _MSC_FULL_VER
 /* Thread name available only for VC-compiler */

Modified: libmicrohttpd/src/microhttpd/mhd_threads.h
===================================================================
--- libmicrohttpd/src/microhttpd/mhd_threads.h  2016-08-10 13:52:38 UTC (rev 
37685)
+++ libmicrohttpd/src/microhttpd/mhd_threads.h  2016-08-10 13:52:43 UTC (rev 
37686)
@@ -58,7 +58,8 @@
 
 #ifndef MHD_NO_THREAD_NAMES
 #  if defined(MHD_USE_POSIX_THREADS)
-#    ifdef HAVE_PTHREAD_SETNAME_NP
+#    if defined(HAVE_PTHREAD_SETNAME_NP_GNU) || 
defined(HAVE_PTHREAD_SET_NAME_NP_FREEBSD) \
+        defined(HAVE_PTHREAD_SETNAME_NP_DARWIN) || 
defined(HAVE_PTHREAD_SETNAME_NP_NETBSD)
 #      define MHD_USE_THREAD_NAME_
 #    endif /* HAVE_PTHREAD_SETNAME_NP */
 #  elif defined(MHD_USE_W32_THREADS)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]