From 9aae539d4cfbf68a367360617cefc5a2c0389b6a Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 30 Jul 2019 14:32:47 +0000 Subject: [PATCH] libcxx: Define __STDCPP_THREADS__ to 1, not to __cplusplus. [cpp.predefined]p2: __STDCPP_THREADS__ Defined, and has the value integer literal 1, if and only if a program can have more than one thread of execution . Also define it only if it's not defined already, since it's supposed to be defined by the compiler. Also move it from thread to __config (which requires setting it only if _LIBCPP_HAS_NO_THREADS is not defined). Part of PR33230. The intent is to eventually make the compiler define this instead. llvm-svn: 367316 --- libcxx/include/__config | 8 ++++++++ libcxx/include/thread | 4 ---- libcxx/test/std/thread/macro.pass.cpp | 4 +++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/libcxx/include/__config b/libcxx/include/__config index 682b990..e49adb4 100644 --- a/libcxx/include/__config +++ b/libcxx/include/__config @@ -1097,6 +1097,14 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container( _LIBCPP_HAS_NO_THREADS is defined. #endif +#if defined(__STDCPP_THREADS__) && defined(_LIBCPP_HAS_NO_THREADS) +#error _LIBCPP_HAS_NO_THREADS cannot be set when __STDCPP_THREADS__ is set. +#endif + +#if !defined(_LIBCPP_HAS_NO_THREADS) && !defined(__STDCPP_THREADS__) +#define __STDCPP_THREADS__ 1 +#endif + // The glibc and Bionic implementation of pthreads implements // pthread_mutex_destroy as nop for regular mutexes. Additionally, Win32 // mutexes have no destroy mechanism. diff --git a/libcxx/include/thread b/libcxx/include/thread index 3d8d2ac..4277bc9 100644 --- a/libcxx/include/thread +++ b/libcxx/include/thread @@ -14,8 +14,6 @@ thread synopsis -#define __STDCPP_THREADS__ __cplusplus - namespace std { @@ -107,8 +105,6 @@ void sleep_for(const chrono::duration& rel_time); _LIBCPP_PUSH_MACROS #include <__undef_macros> -#define __STDCPP_THREADS__ __cplusplus - #ifdef _LIBCPP_HAS_NO_THREADS #error is not supported on this single threaded system #else // !_LIBCPP_HAS_NO_THREADS diff --git a/libcxx/test/std/thread/macro.pass.cpp b/libcxx/test/std/thread/macro.pass.cpp index 0c16a0d0..5d24d5f 100644 --- a/libcxx/test/std/thread/macro.pass.cpp +++ b/libcxx/test/std/thread/macro.pass.cpp @@ -10,7 +10,7 @@ // -// #define __STDCPP_THREADS__ __cplusplus +// #define __STDCPP_THREADS__ 1 #include @@ -20,6 +20,8 @@ int main(int, char**) { #ifndef __STDCPP_THREADS__ #error __STDCPP_THREADS__ is not defined +#elif __STDCPP_THREADS__ != 1 +#error __STDCPP_THREADS__ has the wrong value #endif return 0; -- 2.7.4