Commit 8a6f12e1 authored by Nikita Lutsenko's avatar Nikita Lutsenko Committed by Facebook Github Bot

folly | Fix folly::setThreadName, folly::getThreadName on iOS/watchOS/tvOS.

Summary:
According to headers, `pthread_getname_np` and `pthread_setname_np` are available since iOS 3.2 and macOS 10.6.
However, guarding just on min macOS version isn't going to work for iOS/watchOS/tvOS, because it's very rarely defined.
So add another case for when `__IPHONE_OS_VERSION_MIN_REQUIRED` is defined and is above iOS 3.2, which will also make watchOS and tvOS work.

Reviewed By: yfeldblum

Differential Revision: D7648204

fbshipit-source-id: 1e608cdad3f39242eff79fbb6da8e560eeee720a
parent 98174e06
...@@ -34,12 +34,17 @@ namespace folly { ...@@ -34,12 +34,17 @@ namespace folly {
#endif #endif
#endif #endif
#if defined(__APPLE__) && defined(__MAC_OS_X_VERSION_MIN_REQUIRED) #if defined(__APPLE__)
#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060 #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && \
// has pthread_setname_np(const char*) (1 param) __MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
// macOS 10.6+ has pthread_setname_np(const char*) (1 param)
#define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 1
#elif defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && \
__IPHONE_OS_VERSION_MIN_REQUIRED >= 30200
// iOS 3.2+ has pthread_setname_np(const char*) (1 param)
#define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 1 #define FOLLY_HAS_PTHREAD_SETNAME_NP_NAME 1
#endif #endif
#endif #endif // defined(__APPLE__)
namespace { namespace {
...@@ -151,8 +156,8 @@ bool setThreadName(std::thread::id tid, StringPiece name) { ...@@ -151,8 +156,8 @@ bool setThreadName(std::thread::id tid, StringPiece name) {
#if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME #if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME
return 0 == pthread_setname_np(id, buf); return 0 == pthread_setname_np(id, buf);
#elif FOLLY_HAS_PTHREAD_SETNAME_NP_NAME #elif FOLLY_HAS_PTHREAD_SETNAME_NP_NAME
// Since OS X 10.6 it is possible for a thread to set its own name, // Since macOS 10.6 and iOS 3.2 it is possible for a thread to set its own
// but not that of some other thread. // name, but not that of some other thread.
if (pthread_equal(pthread_self(), id)) { if (pthread_equal(pthread_self(), id)) {
return 0 == pthread_setname_np(buf); return 0 == pthread_setname_np(buf);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment