Commit 1244eb24 authored by Christopher Dykes's avatar Christopher Dykes Committed by Facebook Github Bot

Add FOLLY_HAVE_PTRHEAD

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