Add FOLLY_HAVE_PTRHEAD
authorChristopher Dykes <cdykes@fb.com>
Fri, 14 Apr 2017 20:53:52 +0000 (13:53 -0700)
committerFacebook Github Bot <facebook-github-bot@users.noreply.github.com>
Fri, 14 Apr 2017 21:05:01 +0000 (14:05 -0700)
Summary:
Folly is gaining support for compiling without PThread support on Windows, but we need a way to know that at compile-time for certain APIs.
This also includes changes to guard the only API outside of portability/PThread.h that needs to be guarded on the existence of PThread.

Reviewed By: yfeldblum

Differential Revision: D4889526

fbshipit-source-id: 21175ad90f60a47718c7e2775e3b429b2aad62e2

folly/ThreadName.h
folly/configure.ac

index 0a5e59984bb94a0a258ea14156bf04b8112f6c9b..ad773033a6252970c69e86130c31833a5593583e 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <folly/Range.h>
 #include <folly/Traits.h>
+#include <folly/portability/Config.h>
 #include <folly/portability/PThread.h>
 
 namespace folly {
@@ -43,9 +44,11 @@ namespace folly {
 template <typename T>
 inline bool setThreadName(T /* id */, StringPiece /* name */) {
   static_assert(
+#if FOLLY_HAVE_PTHREAD
       std::is_same<T, pthread_t>::value ||
-          std::is_same<T, std::thread::id>::value ||
-          std::is_same<T, std::thread::native_handle_type>::value,
+#endif
+      std::is_same<T, std::thread::id>::value ||
+      std::is_same<T, std::thread::native_handle_type>::value,
       "type must be pthread_t, std::thread::id or "
       "std::thread::native_handle_type");
   return false;
@@ -70,6 +73,7 @@ inline bool setThreadName(pthread_t id, StringPiece name) {
 }
 #endif
 
+#if FOLLY_HAVE_PTHREAD
 template <
     typename = folly::_t<std::enable_if<
         std::is_same<pthread_t, std::thread::native_handle_type>::value>>>
@@ -88,5 +92,10 @@ inline bool setThreadName(std::thread::id id, StringPiece name) {
 inline bool setThreadName(StringPiece name) {
   return setThreadName(pthread_self(), name);
 }
+#else 
+inline bool setThreadName(StringPiece name) {
+  return false;
+}
+#endif
 
 }
index 22e2f9fae8937bd2d7c58a32e2b9d06b0a3e6f2e..4e951b74386fd769f342851860eea1e49e4905b8 100644 (file)
@@ -326,6 +326,8 @@ if test "$folly_cv_lib_liblinux_vdso" = yes; then
   AC_DEFINE([HAVE_LINUX_VDSO], [1], [Define to 1 if liblinux-vdso is available])
 fi
 
+AC_DEFINE([HAVE_PTHREAD], [1], [Define to 1 if pthread is avaliable])
+
 AC_CACHE_CHECK(
   [for usable std::is_trivially_copyable],
   [folly_cv_decl_std_is_trivially_copyable],