summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 02:57:14 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-12-03 02:57:14 +0000
commitdfe27428f10723ceba099934ddcb0f07e9f3790b (patch)
treeb94c80436228816673beda30e099769541ffe5b4
parent2962b6e063e4e6e8bd4b8be5c45166972caf41c2 (diff)
downloadruby-dfe27428f10723ceba099934ddcb0f07e9f3790b.tar.gz
configure.in: split SET_THREAD_NAME
* configure.in: separate SET_CURRENT_THREAD_NAME, which can set the name of current thread only, and SET_ANOTHER_THREAD_NAME, which can set the name of other threads. * thread.c (rb_thread_setname): use SET_ANOTHER_THREAD_NAME. OS X is not possible to set another thread name. * thread_pthread.c (native_set_thread_name, thread_timer): use SET_CURRENT_THREAD_NAME. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52866 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog12
-rw-r--r--configure.in13
-rw-r--r--thread.c16
-rw-r--r--thread_pthread.c13
4 files changed, 33 insertions, 21 deletions
diff --git a/ChangeLog b/ChangeLog
index fb1cd6cbe0..365ace3abe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+Thu Dec 3 11:57:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * configure.in: separate SET_CURRENT_THREAD_NAME, which can set
+ the name of current thread only, and SET_ANOTHER_THREAD_NAME,
+ which can set the name of other threads.
+
+ * thread.c (rb_thread_setname): use SET_ANOTHER_THREAD_NAME. OS X
+ is not possible to set another thread name.
+
+ * thread_pthread.c (native_set_thread_name, thread_timer): use
+ SET_CURRENT_THREAD_NAME.
+
Wed Dec 02 22:57:46 2015 Koichi Sasada <ko1@atdot.net>
* vm_core.h, iseq.h: remove rb_iseq_t::variable_body.
diff --git a/configure.in b/configure.in
index 24014c0597..134e024d0c 100644
--- a/configure.in
+++ b/configure.in
@@ -2890,6 +2890,7 @@ if test x"$enable_pthread" = xyes; then
else
AC_CHECK_FUNCS(pthread_attr_init)
fi
+ set_current_thread_name=
if test "$ac_cv_func_pthread_setname_np" = yes; then
AC_CACHE_CHECK([arguments of pthread_setname_np], [rb_cv_func_pthread_setname_np_arguments],
[rb_cv_func_pthread_setname_np_arguments=
@@ -2915,11 +2916,19 @@ if test x"$enable_pthread" = xyes; then
]
)
if test -n "${rb_cv_func_pthread_setname_np_arguments}"; then
- AC_DEFINE_UNQUOTED(SET_THREAD_NAME(name), pthread_setname_np${rb_cv_func_pthread_setname_np_arguments})
+ set_current_thread_name="pthread_setname_np${rb_cv_func_pthread_setname_np_arguments}"
fi
elif test "$ac_cv_func_pthread_set_name_np" = yes; then
- AC_DEFINE_UNQUOTED(SET_THREAD_NAME(name), pthread_set_name_np(pthread_self(), name))
+ set_current_thread_name="pthread_set_name_np(pthread_self(), name)"
fi
+ AS_IF([test -n "$set_current_thread_name"], [
+ AC_DEFINE_UNQUOTED(SET_CURRENT_THREAD_NAME(name), $set_current_thread_name)
+ AS_CASE([$set_current_thread_name],
+ [*'pthread_self()'*], [
+ set_another_thread_name=`echo "$set_current_thread_name" | sed 's/pthread_self()/thid/'`
+ AC_DEFINE_UNQUOTED(SET_ANOTHER_THREAD_NAME(thid,name), $set_another_thread_name)
+ ])
+ ])
fi
if test x"$ac_cv_header_ucontext_h" = xno; then
diff --git a/thread.c b/thread.c
index a14902235e..1444383aa7 100644
--- a/thread.c
+++ b/thread.c
@@ -2774,7 +2774,7 @@ rb_thread_getname(VALUE thread)
static VALUE
rb_thread_setname(VALUE thread, VALUE name)
{
-#if defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP)
+#ifdef SET_ANOTHER_THREAD_NAME
const char *s = "";
#endif
rb_thread_t *th;
@@ -2782,21 +2782,13 @@ rb_thread_setname(VALUE thread, VALUE name)
if (!NIL_P(name)) {
StringValueCStr(name);
name = rb_str_new_frozen(name);
-#if defined(HAVE_PTHREAD_SETNAME_NP) || defined(HAVE_PTHREAD_SET_NAME_NP)
+#ifdef SET_ANOTHER_THREAD_NAME
s = RSTRING_PTR(name);
#endif
}
th->name = name;
-#if defined(HAVE_PTHREAD_SETNAME_NP)
-# if defined(__linux__)
- pthread_setname_np(th->thread_id, s);
-# elif defined(__NetBSD__)
- pthread_setname_np(th->thread_id, s, "%s");
-# elif defined(__APPLE__)
- pthread_setname_np(s);
-# endif
-#elif defined(HAVE_PTHREAD_SET_NAME_NP) /* FreeBSD */
- pthread_set_name_np(th->thread_id, s);
+#if defined(SET_ANOTHER_THREAD_NAME)
+ SET_ANOTHER_THREAD_NAME(th->thread_id, s);
#endif
return name;
}
diff --git a/thread_pthread.c b/thread_pthread.c
index 3804590cc5..6638d53d21 100644
--- a/thread_pthread.c
+++ b/thread_pthread.c
@@ -1481,15 +1481,14 @@ timer_thread_sleep(rb_global_vm_lock_t* unused)
}
#endif /* USE_SLEEPY_TIMER_THREAD */
-#if defined(__linux__) && defined(PR_SET_NAME)
-# undef SET_THREAD_NAME
-# define SET_THREAD_NAME(name) prctl(PR_SET_NAME, name)
+#if !defined(SET_CURRENT_THREAD_NAME) && defined(__linux__) && defined(PR_SET_NAME)
+# define SET_CURRENT_THREAD_NAME(name) prctl(PR_SET_NAME, name)
#endif
static void
native_set_thread_name(rb_thread_t *th)
{
-#ifdef SET_THREAD_NAME
+#ifdef SET_CURRENT_THREAD_NAME
if (!th->first_func && th->first_proc) {
VALUE loc = rb_proc_location(th->first_proc);
if (!NIL_P(loc)) {
@@ -1512,7 +1511,7 @@ native_set_thread_name(rb_thread_t *th)
buf[sizeof(buf)-2] = '*';
buf[sizeof(buf)-1] = '\0';
}
- SET_THREAD_NAME(buf);
+ SET_CURRENT_THREAD_NAME(buf);
}
}
#endif
@@ -1525,8 +1524,8 @@ thread_timer(void *p)
if (TT_DEBUG) WRITE_CONST(2, "start timer thread\n");
-#ifdef SET_THREAD_NAME
- SET_THREAD_NAME("ruby-timer-thr");
+#ifdef SET_CURRENT_THREAD_NAME
+ SET_CURRENT_THREAD_NAME("ruby-timer-thr");
#endif
#if !USE_SLEEPY_TIMER_THREAD