[libc++] Enable <atomic> when threads are disabled
std::atomic is, for the most part, just a thin veneer on top of compiler
builtins. Hence, it should be available even when threads are not available
on the system, and in fact there has been requests for such support.
This patch:
- Moves __libcpp_thread_poll_with_backoff to its own header so it can
be used in <atomic> when threads are disabled.
- Adds a dummy backoff policy for atomic polling that doesn't know about
threads.
- Adjusts the <atomic> feature-test macros so they are provided even when
threads are disabled.
- Runs the <atomic> tests when threads are disabled.
rdar://77873569
Differential Revision: https://reviews.llvm.org/D114109
NOKEYCHECK=True
GitOrigin-RevId: 92832e4889ae6038cc8b3e6e449af2a9b9374ab4
diff --git a/src/memory.cpp b/src/memory.cpp
index 981ab55..4c9bf9f 100644
--- a/src/memory.cpp
+++ b/src/memory.cpp
@@ -8,11 +8,11 @@
#include "memory"
#ifndef _LIBCPP_HAS_NO_THREADS
-#include "mutex"
-#include "thread"
-#if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
-#pragma comment(lib, "pthread")
-#endif
+# include "mutex"
+# include "thread"
+# if defined(__ELF__) && defined(_LIBCPP_LINK_PTHREAD_LIB)
+# pragma comment(lib, "pthread")
+# endif
#endif
#include "include/atomic_support.h"
@@ -130,7 +130,7 @@
return nullptr;
}
-#if !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#if !defined(_LIBCPP_HAS_NO_THREADS)
_LIBCPP_SAFE_STATIC static const std::size_t __sp_mut_count = 16;
_LIBCPP_SAFE_STATIC static __libcpp_mutex_t mut_back[__sp_mut_count] =
@@ -181,7 +181,7 @@
return muts[hash<const void*>()(p) & (__sp_mut_count-1)];
}
-#endif // !defined(_LIBCPP_HAS_NO_ATOMIC_HEADER)
+#endif // !defined(_LIBCPP_HAS_NO_THREADS)
void*
align(size_t alignment, size_t size, void*& ptr, size_t& space)