darwin: assume pthread_setname_np() is available
Stop dlsym-ing the symbol name at run-time, that was only necessary to support macOS and iOS versions that were already near-obsolete when this feature was introduced in August 2013. PR-URL: https://github.com/libuv/libuv/pull/2480 Reviewed-By: Saúl Ibarra Corretgé <s@saghul.net>
This commit is contained in:
parent
038eacfbf4
commit
bee1bf5dd7
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
#include <dlfcn.h>
|
#include <dlfcn.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <pthread.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
@ -36,7 +37,6 @@
|
|||||||
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
|
#define S(s) pCFStringCreateWithCString(NULL, (s), kCFStringEncodingUTF8)
|
||||||
|
|
||||||
|
|
||||||
static int (*dynamic_pthread_setname_np)(const char* name);
|
|
||||||
#if !TARGET_OS_IPHONE
|
#if !TARGET_OS_IPHONE
|
||||||
static CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
|
static CFStringRef (*pCFStringCreateWithCString)(CFAllocatorRef,
|
||||||
const char*,
|
const char*,
|
||||||
@ -77,13 +77,9 @@ UV_DESTRUCTOR(static void uv__set_process_title_platform_fini(void)) {
|
|||||||
|
|
||||||
|
|
||||||
void uv__set_process_title_platform_init(void) {
|
void uv__set_process_title_platform_init(void) {
|
||||||
|
#if !TARGET_OS_IPHONE
|
||||||
OSStatus (*pSetApplicationIsDaemon)(int);
|
OSStatus (*pSetApplicationIsDaemon)(int);
|
||||||
|
|
||||||
/* pthread_setname_np() first appeared in OS X 10.6 and iOS 3.2. */
|
|
||||||
*(void **)(&dynamic_pthread_setname_np) =
|
|
||||||
dlsym(RTLD_DEFAULT, "pthread_setname_np");
|
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
|
||||||
application_services_handle = dlopen("/System/Library/Frameworks/"
|
application_services_handle = dlopen("/System/Library/Frameworks/"
|
||||||
"ApplicationServices.framework/"
|
"ApplicationServices.framework/"
|
||||||
"Versions/A/ApplicationServices",
|
"Versions/A/ApplicationServices",
|
||||||
@ -181,6 +177,8 @@ out:
|
|||||||
|
|
||||||
|
|
||||||
void uv__set_process_title(const char* title) {
|
void uv__set_process_title(const char* title) {
|
||||||
|
char namebuf[64 /* MAXTHREADNAMESIZE */];
|
||||||
|
|
||||||
#if !TARGET_OS_IPHONE
|
#if !TARGET_OS_IPHONE
|
||||||
if (core_foundation_handle != NULL) {
|
if (core_foundation_handle != NULL) {
|
||||||
CFTypeRef asn;
|
CFTypeRef asn;
|
||||||
@ -193,9 +191,6 @@ void uv__set_process_title(const char* title) {
|
|||||||
}
|
}
|
||||||
#endif /* !TARGET_OS_IPHONE */
|
#endif /* !TARGET_OS_IPHONE */
|
||||||
|
|
||||||
if (dynamic_pthread_setname_np != NULL) {
|
uv__strscpy(namebuf, title, sizeof(namebuf));
|
||||||
char namebuf[64]; /* MAXTHREADNAMESIZE */
|
pthread_setname_np(namebuf);
|
||||||
uv__strscpy(namebuf, title, sizeof(namebuf));
|
|
||||||
dynamic_pthread_setname_np(namebuf);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user