diff options
| author | Robert Pluim | 2019-12-19 17:33:16 +0100 |
|---|---|---|
| committer | Robert Pluim | 2020-01-06 15:27:26 +0100 |
| commit | 9063124b9125ed5e2ad87bbb8bd6224526723a92 (patch) | |
| tree | c21c1134698c8d2a131fd387dc3742645c3a1bd2 /src | |
| parent | 088bfcc2d80eed44864147f3491eff69e4eb5cd8 (diff) | |
| download | emacs-9063124b9125ed5e2ad87bbb8bd6224526723a92.tar.gz emacs-9063124b9125ed5e2ad87bbb8bd6224526723a92.zip | |
Use pthread_setname_np to set thread name
* configure.ac: Remove check for sys/prctl.h and prctl, check for
pthread_setname_np instead.
* systhread.c: Remove sys/prctl.h include.
(sys_thread_create) [HAVE_PTHREAD_SETNAME_NP]: Use pthread_setname_np
to set the name of the newly created thread (Bug#38632).
* thread.c (Fmake_thread): Use ENCODE_SYSTEM instead of
ENCODE_UTF_8 on the thread name.
Diffstat (limited to 'src')
| -rw-r--r-- | src/systhread.c | 17 | ||||
| -rw-r--r-- | src/thread.c | 2 |
2 files changed, 12 insertions, 7 deletions
diff --git a/src/systhread.c b/src/systhread.c index c3e4e6a2c5a..1dda036cc2f 100644 --- a/src/systhread.c +++ b/src/systhread.c | |||
| @@ -98,10 +98,6 @@ sys_thread_yield (void) | |||
| 98 | 98 | ||
| 99 | #include <sched.h> | 99 | #include <sched.h> |
| 100 | 100 | ||
| 101 | #ifdef HAVE_SYS_PRCTL_H | ||
| 102 | #include <sys/prctl.h> | ||
| 103 | #endif | ||
| 104 | |||
| 105 | void | 101 | void |
| 106 | sys_mutex_init (sys_mutex_t *mutex) | 102 | sys_mutex_init (sys_mutex_t *mutex) |
| 107 | { | 103 | { |
| @@ -227,9 +223,18 @@ sys_thread_create (sys_thread_t *thread_ptr, const char *name, | |||
| 227 | if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) | 223 | if (!pthread_attr_setdetachstate (&attr, PTHREAD_CREATE_DETACHED)) |
| 228 | { | 224 | { |
| 229 | result = pthread_create (thread_ptr, &attr, func, arg) == 0; | 225 | result = pthread_create (thread_ptr, &attr, func, arg) == 0; |
| 230 | #if defined (HAVE_SYS_PRCTL_H) && defined (HAVE_PRCTL) && defined (PR_SET_NAME) | 226 | #ifdef HAVE_PTHREAD_SETNAME_NP |
| 231 | if (result && name != NULL) | 227 | if (result && name != NULL) |
| 232 | prctl (PR_SET_NAME, name); | 228 | { |
| 229 | /* We need to truncate here otherwise pthread_setname_np | ||
| 230 | fails to set the name. TASK_COMM_LEN is what the length | ||
| 231 | is called in the Linux kernel headers (Bug#38632). */ | ||
| 232 | #define TASK_COMM_LEN 16 | ||
| 233 | char p_name[TASK_COMM_LEN]; | ||
| 234 | strncpy (p_name, name, TASK_COMM_LEN - 1); | ||
| 235 | p_name[TASK_COMM_LEN - 1] = '\0'; | ||
| 236 | pthread_setname_np (*thread_ptr, p_name); | ||
| 237 | } | ||
| 233 | #endif | 238 | #endif |
| 234 | } | 239 | } |
| 235 | 240 | ||
diff --git a/src/thread.c b/src/thread.c index f81163414bb..f7e39dc4273 100644 --- a/src/thread.c +++ b/src/thread.c | |||
| @@ -826,7 +826,7 @@ If NAME is given, it must be a string; it names the new thread. */) | |||
| 826 | new_thread->next_thread = all_threads; | 826 | new_thread->next_thread = all_threads; |
| 827 | all_threads = new_thread; | 827 | all_threads = new_thread; |
| 828 | 828 | ||
| 829 | char const *c_name = !NILP (name) ? SSDATA (ENCODE_UTF_8 (name)) : NULL; | 829 | char const *c_name = !NILP (name) ? SSDATA (ENCODE_SYSTEM (name)) : NULL; |
| 830 | if (c_name) | 830 | if (c_name) |
| 831 | new_thread->thread_name = xstrdup (c_name); | 831 | new_thread->thread_name = xstrdup (c_name); |
| 832 | else | 832 | else |