Commit 0917b8bd authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Fix getCurrentThreadName() on OSX

Summary: OSX was sad. Now it should be happy.

Reviewed By: mzlee

Differential Revision: D5011751

fbshipit-source-id: 77f22ff461036d8530d8f650396d8e12503448e7
parent 0eff88b3
......@@ -60,25 +60,16 @@ bool canSetOtherThreadName() {
static constexpr size_t kMaxThreadNameLength = 16;
Optional<std::string> getCurrentThreadName() {
#if !FOLLY_HAVE_PTHREAD
return Optional<std::string>();
#else
#if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME
#if FOLLY_HAS_PTHREAD_SETNAME_NP_THREAD_NAME || \
FOLLY_HAS_PTHREAD_SETNAME_NP_NAME
std::array<char, kMaxThreadNameLength> buf;
if (pthread_getname_np(pthread_self(), buf.data(), buf.size()) != 0) {
return Optional<std::string>();
}
return make_optional(std::string(buf.data()));
#elif FOLLY_HAS_PTHREAD_SETNAME_NP_NAME
std::array<char, kMaxThreadNameLength> buf;
if (pthread_getname_np(buf.data(), buf.size()) != 0) {
return Optional<std::string>();
}
return make_optional(std::string(buf.data()));
#else
return Optional<std::string>();
#endif
#endif
}
bool setThreadName(std::thread::id tid, StringPiece name) {
......
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