diff options
author | Tom Tromey <tromey@redhat.com> | 2012-08-20 12:17:36 -0600 |
---|---|---|
committer | Tom Tromey <tromey@redhat.com> | 2012-08-20 12:17:36 -0600 |
commit | 68608de20310c42c5719fe99e556847fac9dd1f2 (patch) | |
tree | b656eb2541a476f8f5afdbb710c61347e37bf864 | |
parent | fb77afbe75308507885113a56017f095da8ba1cc (diff) | |
download | emacs-68608de20310c42c5719fe99e556847fac9dd1f2.tar.gz emacs-68608de20310c42c5719fe99e556847fac9dd1f2.tar.bz2 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.ac | 4 | ||||
-rw-r--r-- | src/systhread.c | 16 | ||||
-rw-r--r-- | src/systhread.h | 3 | ||||
-rw-r--r-- | src/thread.c | 7 |
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( linux/version.h sys/systeminfo.h stdio_ext.h fcntl.h coff.h pty.h sys/vlimit.h sys/resource.h - sys/utsname.h pwd.h utmp.h dirent.h util.h) + sys/utsname.h pwd.h utmp.h dirent.h util.h sys/prctl.h) AC_MSG_CHECKING(if personality LINUX32 can be set) AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/personality.h>]], [[personality (PER_LINUX32)]])], @@ -2731,7 +2731,7 @@ gai_strerror mkstemp getline getdelim fsync sync \ difftime posix_memalign \ getpwent endpwent getgrent endgrent \ touchlock \ -cfmakeraw cfsetspeed copysign __executable_start) +cfmakeraw cfsetspeed copysign __executable_start prctl) dnl getwd appears to be buggy on SVR4.2, so we don't use it. if 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/>. */ #include <sched.h> +#ifdef HAVE_SYS_PRCTL_H +#include <sys/prctl.h> +#endif + void sys_mutex_init (sys_mutex_t *mutex) { @@ -91,8 +95,8 @@ sys_thread_equal (sys_thread_t one, sys_thread_t two) } int -sys_thread_create (sys_thread_t *thread_ptr, thread_creation_function *func, - void *arg) +sys_thread_create (sys_thread_t *thread_ptr, const char *name, + thread_creation_function *func, void *arg) { pthread_attr_t attr; int result = 0; @@ -101,7 +105,13 @@ sys_thread_create (sys_thread_t *thread_ptr, thread_creation_function *func, return 0; if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) - result = pthread_create (thread_ptr, &attr, func, arg) == 0; + { + result = pthread_create (thread_ptr, &attr, func, arg) == 0; +#if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME) + if (result && name != NULL) + prctl (PR_SET_NAME, name); +#endif + } pthread_attr_destroy (&attr); 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 *); extern sys_thread_t sys_thread_self (void); extern int sys_thread_equal (sys_thread_t, sys_thread_t); -extern int sys_thread_create (sys_thread_t *, thread_creation_function *, +extern int sys_thread_create (sys_thread_t *, const char *, + thread_creation_function *, void *); extern 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/>. */ #include "character.h" #include "buffer.h" #include "process.h" +#include "coding.h" static struct thread_state primary_thread; @@ -682,6 +683,7 @@ If NAME is given, it names the new thread. */) sys_thread_t thr; struct thread_state *new_thread; Lisp_Object result; + const char *c_name = NULL; /* Can't start a thread in temacs. */ if (!initialized) @@ -716,7 +718,10 @@ If NAME is given, it names the new thread. */) new_thread->next_thread = all_threads; all_threads = new_thread; - if (! sys_thread_create (&thr, run_thread, new_thread)) + if (!NILP (name)) + c_name = SSDATA (ENCODE_UTF_8 (name)); + + if (! sys_thread_create (&thr, c_name, run_thread, new_thread)) { /* Restore the previous situation. */ all_threads = all_threads->next_thread; |