components/pigz/patches/200_named-threads.patch
author Michael Gerdts <mike.gerdts@oracle.com>
Mon, 09 Mar 2015 13:29:15 -0700
changeset 3924 6200b874acbb
parent 2137 components/pigz/patches/named-threads.patch@b1e25f951af0
child 7063 c478967a99d2
permissions -rw-r--r--
20665852 pigz is only multi-threaded with --index

# HG changeset patch
# User Michael Gerdts <[email protected]>
# Date 1412623353 25200
#      Mon Oct 06 12:22:33 2014 -0700
# Node ID 0293c398eda727bf812a867600a25b7831928db7
# Parent  b63f212d891d9cffbc8f4a0e2293532fe44aaa16
name threads to improve observability - developed by Oracle
Not submitted upstream: Uses feature first present in Solaris 12

diff -r b63f212d891d -r 0293c398eda7 yarn.c
--- a/yarn.c
+++ b/yarn.c
@@ -258,7 +258,12 @@
 
 /* not all POSIX implementations create threads as joinable by default, so that
    is made explicit here */
+#ifdef HAVE_PTHREAD_SETNAME_NP
+#undef launch
+thread *launch(const char *probename, void (*probe)(void *), void *payload)
+#else
 thread *launch(void (*probe)(void *), void *payload)
+#endif
 {
     int ret;
     thread *th;
@@ -284,7 +289,9 @@
         (ret = pthread_create(&(th->id), &attr, ignition, capsule)) ||
         (ret = pthread_attr_destroy(&attr)))
         fail(ret);
-
+#ifdef HAVE_PTHREAD_SETNAME_NP
+    (void)pthread_setname_np(th->id, probename);
+#endif
     /* put the thread in the threads list for join_all() */
     th->done = 0;
     th->next = threads;
diff -r b63f212d891d -r 0293c398eda7 yarn.h
--- a/yarn.h
+++ b/yarn.h
@@ -115,7 +115,12 @@
 void yarn_mem(void *(*)(size_t), void (*)(void *));
 
 typedef struct thread_s thread;
+#ifdef HAVE_PTHREAD_SETNAME_NP
+thread *launch(const char *, void (*)(void *), void *);
+#define launch(p, a) launch(#p, p, a)
+#else
 thread *launch(void (*)(void *), void *);
+#endif
 void join(thread *);
 int join_all(void);
 void destruct(thread *);