1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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
This commit is contained in:
nobu 2015-12-03 02:57:14 +00:00
parent 2962b6e063
commit dfe27428f1
4 changed files with 33 additions and 21 deletions

View file

@ -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.

View file

@ -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

View file

@ -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;
}

View file

@ -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