diff options
-rw-r--r-- | configure.ac | 12 | ||||
-rw-r--r-- | pthread_support.c | 18 | ||||
-rw-r--r-- | win32_threads.c | 19 |
3 files changed, 29 insertions, 20 deletions
diff --git a/configure.ac b/configure.ac index 050ad147..09c1f597 100644 --- a/configure.ac +++ b/configure.ac @@ -785,25 +785,25 @@ AS_IF([test "$THREADS" = posix], [AC_MSG_CHECKING(for pthread_setname_np) old_CFLAGS="$CFLAGS" CFLAGS="$CFLAGS $CFLAGS_EXTRA -Werror" - AC_TRY_LINK([#include <pthread.h>], - [pthread_setname_np("thread-name")], + AC_TRY_COMPILE([#include <pthread.h>], + [pthread_setname_np("thread-name")], [AC_MSG_RESULT([yes (w/o tid)]) AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID], [1], [Define to use 'pthread_setname_np(const char*)' function.])], - [AC_TRY_LINK([#include <pthread.h>], - [pthread_setname_np(pthread_self(), "thread-name-%u", 0)], + [AC_TRY_COMPILE([#include <pthread.h>], + [pthread_setname_np(pthread_self(), "thread-name-%u", 0)], [AC_MSG_RESULT([yes (with tid and arg)]) AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG], [1], [Define to use 'pthread_setname_np(pthread_t, const char*, void *)' function.])], - [AC_TRY_LINK([ + [AC_TRY_COMPILE([ #ifdef __CYGWIN__ #define _GNU_SOURCE 1 #elif defined(__linux__) || defined(__GLIBC__) || defined(__GNU__) #define _GNU_SOURCE 1 #endif #include <pthread.h>], - [pthread_setname_np(pthread_self(), "thread-name")], + [pthread_setname_np(pthread_self(), "thread-name")], [AC_MSG_RESULT([yes (with tid)]) AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_WITH_TID], [1], [Define to use 'pthread_setname_np(pthread_t, const char*)' diff --git a/pthread_support.c b/pthread_support.c index b0d250b1..c1a6b21e 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -349,19 +349,23 @@ static ptr_t marker_sp[MAX_MARKERS - 1] = {0}; || defined(HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID) static void set_marker_thread_name(unsigned id) { -# if defined(__STRICT_ANSI__) -# define name_buf "GC-marker" -# else - char name_buf[16]; /* pthread_setname_np may fail for longer names */ - (void)snprintf(name_buf, sizeof(name_buf), "GC-marker-%u", id); -# endif + char name_buf[16]; /* pthread_setname_np may fail for longer names */ + int len = sizeof("GC-marker-") - 1; + + /* Compose the name manually as snprintf may be unavailable or */ + /* "%u directive output may be truncated" warning may occur. */ + BCOPY("GC-marker-", name_buf, len); + if (id >= 10) + name_buf[len++] = (char)('0' + (id / 10) % 10); + name_buf[len] = (char)('0' + id % 10); + name_buf[len + 1] = '\0'; + # ifdef HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID /* iOS, OS X */ (void)pthread_setname_np(name_buf); # else /* Linux, Solaris, etc. */ if (pthread_setname_np(pthread_self(), name_buf) != 0) WARN("pthread_setname_np failed\n", 0); # endif -# undef name_buf } #else # define set_marker_thread_name(id) (void)(id) diff --git a/win32_threads.c b/win32_threads.c index a7087d70..6f6ed56a 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2004,15 +2004,20 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, # if defined(HAVE_PTHREAD_SETNAME_NP_WITH_TID) static void set_marker_thread_name(unsigned id) { -# if defined(__STRICT_ANSI__) -# define name_buf "GC-marker" -# else - char name_buf[16]; /* pthread_setname_np may fail for longer names */ - (void)snprintf(name_buf, sizeof(name_buf), "GC-marker-%u", id); -# endif + /* This code is the same as in pthread_support.c. */ + char name_buf[16]; /* pthread_setname_np may fail for longer names */ + int len = sizeof("GC-marker-") - 1; + + /* Compose the name manually as snprintf may be unavailable or */ + /* "%u directive output may be truncated" warning may occur. */ + BCOPY("GC-marker-", name_buf, len); + if (id >= 10) + name_buf[len++] = (char)('0' + (id / 10) % 10); + name_buf[len] = (char)('0' + id % 10); + name_buf[len + 1] = '\0'; + if (pthread_setname_np(pthread_self(), name_buf) != 0) WARN("pthread_setname_np failed\n", 0); -# undef name_buf } # else # define set_marker_thread_name(id) (void)(id) |