diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2020-02-06 12:24:15 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2020-02-06 13:07:25 +0300 |
commit | ab91e4e84d166fb7536056ae95d55c00d2ea2f46 (patch) | |
tree | 2aeb2809ddd992011880e66b54275f89326281d9 /win32_threads.c | |
parent | 9eddcfa3233581e24676967d5734e5a4f1b2c7be (diff) | |
download | bdwgc-ab91e4e84d166fb7536056ae95d55c00d2ea2f46.tar.gz |
Set name of GC marker threads
Issue #300 (bdwgc).
The threads are named as "GC-marker-<n>".
For now, the detection of pthread_setname_np availability and kind is
implemented in configure only.
On Darwin, the GC mprotect thread name is set too.
* configure.ac [$THREADS==posix] (HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID,
HAVE_PTHREAD_SETNAME_NP_WITH_TID_AND_ARG,
HAVE_PTHREAD_SETNAME_NP_WITH_TID): Check for pthread_setname_np; set
the relevant HAVE_x macro.
* include/private/gc_priv.h [__CYGWIN__ && GC_THREADS && !_GNU_SOURCE]
(_GNU_SOURCE): Define.
* os_dep.c [MPROTECT_VDB && DARWIN
&& HAVE_PTHREAD_SETNAME_NP_WITHOUT_TID] (GC_mprotect_thread): Call
pthread_setname_np().
* pthread_support.c [PARALLEL_MARK] (set_marker_thread_name): Define.
* win32_threads.c [PARALLEL_MARK] (set_marker_thread_name): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Call
set_marker_thread_name(id).
* win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
Diffstat (limited to 'win32_threads.c')
-rw-r--r-- | win32_threads.c | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/win32_threads.c b/win32_threads.c index 88e54a5b..a7087d70 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2001,6 +2001,23 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, /* only a few entries). */ # endif +# 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 + 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) +# endif + /* GC_mark_thread() is the same as in pthread_support.c */ # ifdef GC_PTHREADS_PARAMARK STATIC void * GC_mark_thread(void * id) @@ -2013,6 +2030,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, word my_mark_no = 0; if ((word)id == GC_WORD_MAX) return 0; /* to prevent a compiler warning */ + set_marker_thread_name((unsigned)(word)id); marker_sp[(word)id] = GC_approx_sp(); # ifdef IA64 marker_bsp[(word)id] = GC_save_regs_in_stack(); |