Skip to content

Commit a1bc823

Browse files
committed
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. llvm-svn: 302734
1 parent 40a87a9 commit a1bc823

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

libcxx/include/__config

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,12 @@
129129

130130
#define __has_keyword(__x) !(__is_identifier(__x))
131131

132+
#ifdef __has_include
133+
#define __libcpp_has_include(__x) __has_include(__x)
134+
#else
135+
#define __libcpp_has_include(__x) 0
136+
#endif
137+
132138
#if defined(__clang__)
133139
#define _LIBCPP_COMPILER_CLANG
134140
# ifndef __apple_build_version__
@@ -980,6 +986,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
980986
// Thread API
981987
#if !defined(_LIBCPP_HAS_NO_THREADS) && \
982988
!defined(_LIBCPP_HAS_THREAD_API_PTHREAD) && \
989+
!defined(_LIBCPP_HAS_THREAD_API_WIN32) && \
983990
!defined(_LIBCPP_HAS_THREAD_API_EXTERNAL)
984991
# if defined(__FreeBSD__) || \
985992
defined(__Fuchsia__) || \
@@ -988,7 +995,7 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
988995
defined(__APPLE__) || \
989996
defined(__CloudABI__) || \
990997
defined(__sun__) || \
991-
defined(__WINPTHREADS_VERSION)
998+
(defined(__MINGW32__) && __libcpp_has_include(<pthread.h>))
992999
# define _LIBCPP_HAS_THREAD_API_PTHREAD
9931000
# elif defined(_LIBCPP_WIN32API)
9941001
# define _LIBCPP_HAS_THREAD_API_WIN32

0 commit comments

Comments
 (0)