mirror of
https://codeberg.org/dnkl/foot.git
synced 2026-02-04 04:06:06 -05:00
render: set thread name in a portable way
prctl is Linux-only but pthread_setname_np is same as PR_SET_NAME.
Solaris and FreeBSD >= 13 have pthread_setname_np similar to Linux.
DragonFly, OpenBSD, FreeBSD < 13 lack pthread_setname_np but provide
pthread_set_name_np which doesn't return a value. NetBSD requires 3
arguments for pthread_setname_np where the last one is void *.
render.c:8:10: fatal error: 'sys/prctl.h' file not found
#include <sys/prctl.h>
^~~~~~~~~~~~~
render.c🔢9: error: implicit declaration of function 'prctl' is invalid in C99 [-Werror,-Wimplicit-function-declaration]
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
render.c🔢15: error: use of undeclared identifier 'PR_SET_NAME'
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
^
This commit is contained in:
parent
db9dc7e908
commit
f2ad02aaab
1 changed files with 8 additions and 2 deletions
10
render.c
10
render.c
|
|
@ -5,7 +5,13 @@
|
|||
#include <sys/ioctl.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/timerfd.h>
|
||||
#include <sys/prctl.h>
|
||||
#include <pthread.h>
|
||||
#if __has_include(<pthread_np.h>)
|
||||
#include <pthread_np.h>
|
||||
#define pthread_setname_np(thread, name) (pthread_set_name_np(thread, name), 0)
|
||||
#elif defined(__NetBSD__)
|
||||
#define pthread_setname_np(thread, name) pthread_setname_np(thread, "%s", (void *)name)
|
||||
#endif
|
||||
|
||||
#include <wayland-cursor.h>
|
||||
#include <xdg-shell.h>
|
||||
|
|
@ -1231,7 +1237,7 @@ render_worker_thread(void *_ctx)
|
|||
char proc_title[16];
|
||||
snprintf(proc_title, sizeof(proc_title), "foot:render:%d", my_id);
|
||||
|
||||
if (prctl(PR_SET_NAME, proc_title, 0, 0, 0) < 0)
|
||||
if (pthread_setname_np(pthread_self(), proc_title) < 0)
|
||||
LOG_ERRNO("render worker %d: failed to set process title", my_id);
|
||||
|
||||
sem_t *start = &term->render.workers.start;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue