aboutsummaryrefslogtreecommitdiff
path: root/src/unix/darwin-proctitle.c
diff options
context:
space:
mode:
authorSantiago Gimeno <santiago.gimeno@gmail.com>2024-11-27 12:52:18 +0100
committerGitHub <noreply@github.com>2024-11-27 12:52:18 +0100
commit61c966cf0b4b6b5fc44d5ab3678cf5d0caef249d (patch)
treeb40a8e28b1eb0b2c31e05bd16f682511619a544d /src/unix/darwin-proctitle.c
parentb7d07d78e976acc453c9ba8f8409650c2ad8a585 (diff)
downloadlibuv-61c966cf0b4b6b5fc44d5ab3678cf5d0caef249d.tar.gz
libuv-61c966cf0b4b6b5fc44d5ab3678cf5d0caef249d.zip
src: add uv_thread_set/getname() methods (#4599)
`uv_thread_setname()` sets the name of the current thread. Different platforms define different limits on the max number of characters a thread name can be: Linux, IBMi (16), macOS (64), Windows (32767), and NetBSD (32), etc. `uv_thread_setname()` will truncate it in case `name` is larger than the limit of the platform. `uv_thread_getname()` gets the name of the thread specified by `tid`. The thread name is copied into the buffer pointed to by `name`. The `size` parameter specifies the size of the buffer pointed to by `name`. The buffer should be large enough to hold the name of the thread plus the trailing NUL, or it will be truncated to fit.
Diffstat (limited to 'src/unix/darwin-proctitle.c')
-rw-r--r--src/unix/darwin-proctitle.c20
1 files changed, 2 insertions, 18 deletions
diff --git a/src/unix/darwin-proctitle.c b/src/unix/darwin-proctitle.c
index 5288083e..5e564297 100644
--- a/src/unix/darwin-proctitle.c
+++ b/src/unix/darwin-proctitle.c
@@ -33,25 +33,9 @@
#include "darwin-stub.h"
#endif
-
-static int uv__pthread_setname_np(const char* name) {
- char namebuf[64]; /* MAXTHREADNAMESIZE */
- int err;
-
- strncpy(namebuf, name, sizeof(namebuf) - 1);
- namebuf[sizeof(namebuf) - 1] = '\0';
-
- err = pthread_setname_np(namebuf);
- if (err)
- return UV__ERR(err);
-
- return 0;
-}
-
-
int uv__set_process_title(const char* title) {
#if TARGET_OS_IPHONE
- return uv__pthread_setname_np(title);
+ return uv__thread_setname(title);
#else
CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
const char*,
@@ -177,7 +161,7 @@ int uv__set_process_title(const char* title) {
goto out;
}
- uv__pthread_setname_np(title); /* Don't care if it fails. */
+ uv__thread_setname(title); /* Don't care if it fails. */
err = 0;
out: