aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2012-08-20 12:17:36 -0600
committerTom Tromey2012-08-20 12:17:36 -0600
commit68608de20310c42c5719fe99e556847fac9dd1f2 (patch)
treeb656eb2541a476f8f5afdbb710c61347e37bf864
parentfb77afbe75308507885113a56017f095da8ba1cc (diff)
downloademacs-68608de20310c42c5719fe99e556847fac9dd1f2.tar.gz
emacs-68608de20310c42c5719fe99e556847fac9dd1f2.zip
pass the thread name to the OS if possible
use prctl to pass the thread name to the OS, if possible
-rw-r--r--configure.ac4
-rw-r--r--src/systhread.c16
-rw-r--r--src/systhread.h3
-rw-r--r--src/thread.c7
4 files changed, 23 insertions, 7 deletions
diff --git a/configure.ac b/configure.ac
index 2394790c455..90c0ef07aa1 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1230,7 +1230,7 @@ AC_CHECK_HEADERS_ONCE(
1230 linux/version.h sys/systeminfo.h 1230 linux/version.h sys/systeminfo.h
1231 stdio_ext.h fcntl.h coff.h pty.h 1231 stdio_ext.h fcntl.h coff.h pty.h
1232 sys/vlimit.h sys/resource.h 1232 sys/vlimit.h sys/resource.h
1233 sys/utsname.h pwd.h utmp.h dirent.h util.h) 1233 sys/utsname.h pwd.h utmp.h dirent.h util.h sys/prctl.h)
1234 1234
1235AC_MSG_CHECKING(if personality LINUX32 can be set) 1235AC_MSG_CHECKING(if personality LINUX32 can be set)
1236AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/personality.h>]], [[personality (PER_LINUX32)]])], 1236AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/personality.h>]], [[personality (PER_LINUX32)]])],
@@ -2731,7 +2731,7 @@ gai_strerror mkstemp getline getdelim fsync sync \
2731difftime posix_memalign \ 2731difftime posix_memalign \
2732getpwent endpwent getgrent endgrent \ 2732getpwent endpwent getgrent endgrent \
2733touchlock \ 2733touchlock \
2734cfmakeraw cfsetspeed copysign __executable_start) 2734cfmakeraw cfsetspeed copysign __executable_start prctl)
2735 2735
2736dnl getwd appears to be buggy on SVR4.2, so we don't use it. 2736dnl getwd appears to be buggy on SVR4.2, so we don't use it.
2737if test $opsys = unixware; then 2737if test $opsys = unixware; then
diff --git a/src/systhread.c b/src/systhread.c
index 666641c24da..ab647528452 100644
--- a/src/systhread.c
+++ b/src/systhread.c
@@ -24,6 +24,10 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
24 24
25#include <sched.h> 25#include <sched.h>
26 26
27#ifdef HAVE_SYS_PRCTL_H
28#include <sys/prctl.h>
29#endif
30
27void 31void
28sys_mutex_init (sys_mutex_t *mutex) 32sys_mutex_init (sys_mutex_t *mutex)
29{ 33{
@@ -91,8 +95,8 @@ sys_thread_equal (sys_thread_t one, sys_thread_t two)
91} 95}
92 96
93int 97int
94sys_thread_create (sys_thread_t *thread_ptr, thread_creation_function *func, 98sys_thread_create (sys_thread_t *thread_ptr, const char *name,
95 void *arg) 99 thread_creation_function *func, void *arg)
96{ 100{
97 pthread_attr_t attr; 101 pthread_attr_t attr;
98 int result = 0; 102 int result = 0;
@@ -101,7 +105,13 @@ sys_thread_create (sys_thread_t *thread_ptr, thread_creation_function *func,
101 return 0; 105 return 0;
102 106
103 if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) 107 if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED))
104 result = pthread_create (thread_ptr, &attr, func, arg) == 0; 108 {
109 result = pthread_create (thread_ptr, &attr, func, arg) == 0;
110#if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME)
111 if (result && name != NULL)
112 prctl (PR_SET_NAME, name);
113#endif
114 }
105 115
106 pthread_attr_destroy (&attr); 116 pthread_attr_destroy (&attr);
107 117
diff --git a/src/systhread.h b/src/systhread.h
index 790b385b7ff..bbd242ab93c 100644
--- a/src/systhread.h
+++ b/src/systhread.h
@@ -54,7 +54,8 @@ extern void sys_cond_destroy (sys_cond_t *);
54extern sys_thread_t sys_thread_self (void); 54extern sys_thread_t sys_thread_self (void);
55extern int sys_thread_equal (sys_thread_t, sys_thread_t); 55extern int sys_thread_equal (sys_thread_t, sys_thread_t);
56 56
57extern int sys_thread_create (sys_thread_t *, thread_creation_function *, 57extern int sys_thread_create (sys_thread_t *, const char *,
58 thread_creation_function *,
58 void *); 59 void *);
59 60
60extern void sys_thread_yield (void); 61extern void sys_thread_yield (void);
diff --git a/src/thread.c b/src/thread.c
index dba84fd0fb6..01d2fd0d6eb 100644
--- a/src/thread.c
+++ b/src/thread.c
@@ -23,6 +23,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23#include "character.h" 23#include "character.h"
24#include "buffer.h" 24#include "buffer.h"
25#include "process.h" 25#include "process.h"
26#include "coding.h"
26 27
27static struct thread_state primary_thread; 28static struct thread_state primary_thread;
28 29
@@ -682,6 +683,7 @@ If NAME is given, it names the new thread. */)
682 sys_thread_t thr; 683 sys_thread_t thr;
683 struct thread_state *new_thread; 684 struct thread_state *new_thread;
684 Lisp_Object result; 685 Lisp_Object result;
686 const char *c_name = NULL;
685 687
686 /* Can't start a thread in temacs. */ 688 /* Can't start a thread in temacs. */
687 if (!initialized) 689 if (!initialized)
@@ -716,7 +718,10 @@ If NAME is given, it names the new thread. */)
716 new_thread->next_thread = all_threads; 718 new_thread->next_thread = all_threads;
717 all_threads = new_thread; 719 all_threads = new_thread;
718 720
719 if (! sys_thread_create (&thr, run_thread, new_thread)) 721 if (!NILP (name))
722 c_name = SSDATA (ENCODE_UTF_8 (name));
723
724 if (! sys_thread_create (&thr, c_name, run_thread, new_thread))
720 { 725 {
721 /* Restore the previous situation. */ 726 /* Restore the previous situation. */
722 all_threads = all_threads->next_thread; 727 all_threads = all_threads->next_thread;