[libcxx] r302734 - Fix MinGW build to use Pthread when the header is available.

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Wed May 10 14:34:58 PDT 2017


Author: ericwf
Date: Wed May 10 16:34:58 2017
New Revision: 302734

URL: http://llvm.org/viewvc/llvm-project?rev=302734&view=rev
Log:
Fix MinGW build to use Pthread when the header is available.

Some MinGW configurations use WinPThread instead of the native
threading interfaces. When this happens libc++ doesn't build because
it tries to use the wrong threading API.

This patch attempts to correctly detect and enable pthreads; Selecting
them when __MINGW32__ is defined and __has_include(<pthread.h>) is true.
I'm not sure if this works correctly 100% of the time but it seemed
like the most correct approach available.

Modified:
    libcxx/trunk/include/__config

Modified: libcxx/trunk/include/__config
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/__config?rev=302734&r1=302733&r2=302734&view=diff
==============================================================================
--- libcxx/trunk/include/__config (original)
+++ libcxx/trunk/include/__config Wed May 10 16:34:58 2017
@@ -129,6 +129,12 @@
 
 #define __has_keyword(__x) !(__is_identifier(__x))
 
+#ifdef __has_include
+#define __libcpp_has_include(__x) __has_include(__x)
+#else
+#define __libcpp_has_include(__x) 0
+#endif
+
 #if defined(__clang__)
 #define _LIBCPP_COMPILER_CLANG
 # ifndef __apple_build_version__
@@ -980,6 +986,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
 // Thread API
 #if !defined(_LIBCPP_HAS_NO_THREADS) && \
     !defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
+    !defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
     !defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
 # if defined(__FreeBSD__) || \
     defined(__Fuchsia__) || \
@@ -988,7 +995,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanit
     defined(__APPLE__) || \
     defined(__CloudABI__) || \
     defined(__sun__) || \
-    defined(__WINPTHREADS_VERSION)
+    (defined(__MINGW32__) && __libcpp_has_include(<pthread.h>))
 #   define _LIBCPP_HAS_THREAD_API_PTHREAD
 # elif defined(_LIBCPP_WIN32API)
 #  define _LIBCPP_HAS_THREAD_API_WIN32




More information about the cfe-commits mailing list