darwin: call pthread_setname_np() if available
When setting the process title, also call pthread_setname_np() when supported (OS X >= 10.6 and iOS >= 3.2.)
This commit is contained in:
parent
c82e7033a5
commit
5ff6f85f58
@ -19,6 +19,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include <TargetConditionals.h>
|
#include <TargetConditionals.h>
|
||||||
|
#include <dlfcn.h>
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
#if !TARGET_OS_IPHONE
|
||||||
# include <CoreFoundation/CoreFoundation.h>
|
# include <CoreFoundation/CoreFoundation.h>
|
||||||
@ -26,9 +27,30 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
static int uv__pthread_setname_np(const char* name) {
|
||||||
|
int (*dynamic_pthread_setname_np)(const char* name);
|
||||||
|
char namebuf[64]; /* MAXTHREADNAMESIZE */
|
||||||
|
int err;
|
||||||
|
|
||||||
|
/* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
|
||||||
|
dynamic_pthread_setname_np = dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
||||||
|
if (dynamic_pthread_setname_np == NULL)
|
||||||
|
return -ENOSYS;
|
||||||
|
|
||||||
|
strncpy(namebuf, name, sizeof(namebuf) - 1);
|
||||||
|
namebuf[sizeof(namebuf) - 1] = '\0';
|
||||||
|
|
||||||
|
err = dynamic_pthread_setname_np(namebuf);
|
||||||
|
if (err)
|
||||||
|
return -err;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
int uv__set_process_title(const char* title) {
|
int uv__set_process_title(const char* title) {
|
||||||
#if TARGET_OS_IPHONE
|
#if TARGET_OS_IPHONE
|
||||||
return -ENOSYS;
|
return uv__pthread_setname_np(title);
|
||||||
#else
|
#else
|
||||||
typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
|
typedef CFTypeRef (*LSGetCurrentApplicationASNType)(void);
|
||||||
typedef OSStatus (*LSSetApplicationInformationItemType)(int,
|
typedef OSStatus (*LSSetApplicationInformationItemType)(int,
|
||||||
@ -84,6 +106,8 @@ int uv__set_process_title(const char* title) {
|
|||||||
if (err != noErr)
|
if (err != noErr)
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
|
|
||||||
|
uv__pthread_setname_np(title); /* Don't care if it fails. */
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
#endif /* !TARGET_OS_IPHONE */
|
#endif /* !TARGET_OS_IPHONE */
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user