Allow libc++ to be built on systems without POSIX threads
If you're crazy enough to want this sort of thing, then add
-D_LIBCPP_HAS_NO_THREADS to your CXXFLAGS and
--param=additiona_features=libcpp-has-no-threads to your lit commnad line.
http://reviews.llvm.org/D3969
llvm-svn: 217271
Cr-Mirrored-From: sso://chromium.googlesource.com/_direct/external/github.com/llvm/llvm-project
Cr-Mirrored-Commit: b3fcc67f8f13cd95d36ed29d0ae1308decb9e099
diff --git a/include/__mutex_base b/include/__mutex_base
index 293fead..d5ece7c 100644
--- a/include/__mutex_base
+++ b/include/__mutex_base
@@ -22,6 +22,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+#ifndef _LIBCPP_HAS_NO_THREADS
+
class _LIBCPP_TYPE_VIS mutex
{
pthread_mutex_t __m_;
@@ -315,6 +317,7 @@
void __do_timed_wait(unique_lock<mutex>& __lk,
chrono::time_point<chrono::system_clock, chrono::nanoseconds>) _NOEXCEPT;
};
+#endif // !_LIBCPP_HAS_NO_THREADS
template <class _To, class _Rep, class _Period>
inline _LIBCPP_INLINE_VISIBILITY
@@ -332,6 +335,7 @@
return __r;
}
+#ifndef _LIBCPP_HAS_NO_THREADS
template <class _Predicate>
void
condition_variable::wait(unique_lock<mutex>& __lk, _Predicate __pred)
@@ -396,6 +400,8 @@
_VSTD::move(__pred));
}
+#endif // !_LIBCPP_HAS_NO_THREADS
+
_LIBCPP_END_NAMESPACE_STD
#endif // _LIBCPP___MUTEX_BASE
diff --git a/include/atomic b/include/atomic
index 91f1829..b01a59f 100644
--- a/include/atomic
+++ b/include/atomic
@@ -533,6 +533,10 @@
#pragma GCC system_header
#endif
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <atomic> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
_LIBCPP_BEGIN_NAMESPACE_STD
#if !__has_feature(cxx_atomic) && _GNUC_VER < 407
@@ -1779,4 +1783,6 @@
_LIBCPP_END_NAMESPACE_STD
+#endif // !_LIBCPP_HAS_NO_THREADS
+
#endif // _LIBCPP_ATOMIC
diff --git a/include/condition_variable b/include/condition_variable
index dc67266..1af2484 100644
--- a/include/condition_variable
+++ b/include/condition_variable
@@ -115,6 +115,8 @@
#pragma GCC system_header
#endif
+#ifndef _LIBCPP_HAS_NO_THREADS
+
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_TYPE_VIS condition_variable_any
@@ -253,4 +255,6 @@
_LIBCPP_END_NAMESPACE_STD
+#endif // !_LIBCPP_HAS_NO_THREADS
+
#endif // _LIBCPP_CONDITION_VARIABLE
diff --git a/include/future b/include/future
index de00f25..7cd88cb 100644
--- a/include/future
+++ b/include/future
@@ -374,6 +374,10 @@
#pragma GCC system_header
#endif
+#ifndef _LIBCPP_HAS_NO_THREADS
+#error <future> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
_LIBCPP_BEGIN_NAMESPACE_STD
//enum class future_errc
@@ -2612,4 +2616,6 @@
_LIBCPP_END_NAMESPACE_STD
+#endif // !_LIBCPP_HAS_NO_THREADS
+
#endif // _LIBCPP_FUTURE
diff --git a/include/ios b/include/ios
index d95f18a..6d42607 100644
--- a/include/ios
+++ b/include/ios
@@ -216,7 +216,7 @@
#include <__locale>
#include <system_error>
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS
#include <atomic> // for __xindex_
#endif
@@ -367,7 +367,7 @@
int* __index_;
size_t __event_size_;
size_t __event_cap_;
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !_LIBCPP_HAS_NO_THREADS
static atomic<int> __xindex_;
#else
static int __xindex_;
diff --git a/include/memory b/include/memory
index dc9aeba..a9256da 100644
--- a/include/memory
+++ b/include/memory
@@ -610,7 +610,7 @@
#include <cassert>
#endif
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
# include <atomic>
#endif
@@ -5262,7 +5262,7 @@
basic_ostream<_CharT, _Traits>&
operator<<(basic_ostream<_CharT, _Traits>& __os, shared_ptr<_Yp> const& __p);
-#if __has_feature(cxx_atomic)
+#if __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
class _LIBCPP_TYPE_VIS __sp_mut
{
@@ -5388,7 +5388,7 @@
return atomic_compare_exchange_weak(__p, __v, __w);
}
-#endif // __has_feature(cxx_atomic)
+#endif // __has_feature(cxx_atomic) && !defined(_LIBCPP_HAS_NO_THREADS)
//enum class
struct _LIBCPP_TYPE_VIS pointer_safety
diff --git a/include/mutex b/include/mutex
index 5dfba63..9c26356 100644
--- a/include/mutex
+++ b/include/mutex
@@ -187,6 +187,8 @@
_LIBCPP_BEGIN_NAMESPACE_STD
+#ifndef _LIBCPP_HAS_NO_THREADS
+
class _LIBCPP_TYPE_VIS recursive_mutex
{
pthread_mutex_t __m_;
@@ -425,6 +427,8 @@
#endif // _LIBCPP_HAS_NO_VARIADICS
+#endif // !_LIBCPP_HAS_NO_THREADS
+
struct _LIBCPP_TYPE_VIS_ONLY once_flag;
#ifndef _LIBCPP_HAS_NO_VARIADICS
diff --git a/include/shared_mutex b/include/shared_mutex
index 00f816d..9b7f0bf 100644
--- a/include/shared_mutex
+++ b/include/shared_mutex
@@ -112,6 +112,10 @@
#pragma GCC system_header
#endif
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <shared_mutex> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
_LIBCPP_BEGIN_NAMESPACE_STD
class _LIBCPP_TYPE_VIS shared_timed_mutex
@@ -414,6 +418,8 @@
_LIBCPP_END_NAMESPACE_STD
+#endif // !_LIBCPP_HAS_NO_THREADS
+
#endif // _LIBCPP_STD_VER > 11
#endif // _LIBCPP_SHARED_MUTEX
diff --git a/include/thread b/include/thread
index 1f1e4a2..808d76b 100644
--- a/include/thread
+++ b/include/thread
@@ -106,6 +106,10 @@
#define __STDCPP_THREADS__ __cplusplus
+#ifdef _LIBCPP_HAS_NO_THREADS
+#error <thread> is not supported on this single threaded system
+#else // !_LIBCPP_HAS_NO_THREADS
+
_LIBCPP_BEGIN_NAMESPACE_STD
template <class _Tp>
@@ -455,4 +459,6 @@
_LIBCPP_END_NAMESPACE_STD
+#endif // !_LIBCPP_HAS_NO_THREADS
+
#endif // _LIBCPP_THREAD