Fix getCurrentThreadName() on OSX
authorChristopher Dykes <cdykes@fb.com>
Fri, 5 May 2017 19:03:21 +0000 (12:03 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 5 May 2017 19:05:17 +0000 (12:05 -0700)
Summary: OSX was sad. Now it should be happy.

Reviewed By: mzlee

Differential Revision: D5011751

fbshipit-source-id: 77f22ff461036d8530d8f650396d8e12503448e7

folly/ThreadName.cpp

index 97db551f8c5c9dbd2b763849d1eab38b0b4be693..22ead20917e83f9ab58255c333b37eab3b437cdf 100644 (file)
@@ -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) {