[前][次][番号順一覧][スレッド一覧]

ruby-changes:40787

From: nobu <ko1@a...>
Date: Thu, 3 Dec 2015 11:57:33 +0900 (JST)
Subject: [ruby-changes:40787] nobu:r52866 (trunk): configure.in: split SET_THREAD_NAME

nobu	2015-12-03 11:57:14 +0900 (Thu, 03 Dec 2015)

  New Revision: 52866

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=52866

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/configure.in
    trunk/thread.c
    trunk/thread_pthread.c
Index: configure.in
===================================================================
--- configure.in	(revision 52865)
+++ configure.in	(revision 52866)
@@ -2890,6 +2890,7 @@ if test x"$enable_pthread" = xyes; then https://github.com/ruby/ruby/blob/trunk/configure.in#L2890
     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 https://github.com/ruby/ruby/blob/trunk/configure.in#L2916
 	    ]
 	)
 	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
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 52865)
+++ ChangeLog	(revision 52866)
@@ -1,3 +1,15 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Dec  3 11:57:12 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@a...>
 
 	* vm_core.h, iseq.h: remove rb_iseq_t::variable_body.
Index: thread_pthread.c
===================================================================
--- thread_pthread.c	(revision 52865)
+++ thread_pthread.c	(revision 52866)
@@ -1481,15 +1481,14 @@ timer_thread_sleep(rb_global_vm_lock_t* https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1481
 }
 #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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1511
 		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) https://github.com/ruby/ruby/blob/trunk/thread_pthread.c#L1524
 
     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
Index: thread.c
===================================================================
--- thread.c	(revision 52865)
+++ thread.c	(revision 52866)
@@ -2774,7 +2774,7 @@ rb_thread_getname(VALUE thread) https://github.com/ruby/ruby/blob/trunk/thread.c#L2774
 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 na https://github.com/ruby/ruby/blob/trunk/thread.c#L2782
     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;
 }

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]