summaryrefslogtreecommitdiff
path: root/libcxx/src/memory.cpp
diff options
context:
space:
mode:
authorLouis Dionne <ldionne.2@gmail.com>2021-11-17 10:59:31 -0500
committerLouis Dionne <ldionne.2@gmail.com>2021-11-17 23:02:58 -0500
commit92832e4889ae6038cc8b3e6e449af2a9b9374ab4 (patch)
treea89eea92314bda108249cb24e9072dbcf9ff6f12 /libcxx/src/memory.cpp
parentd61840c168a34339aa8e602adf5aba98924a6f61 (diff)
[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
Diffstat (limited to 'libcxx/src/memory.cpp')
-rw-r--r--libcxx/src/memory.cpp14
1 files changed, 7 insertions, 7 deletions
diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp
index 981ab5571edd..4c9bf9f073c8 100644
--- a/libcxx/src/memory.cpp
+++ b/libcxx/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 @@ __shared_weak_count::__get_deleter(const type_info&) const noexcept
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 @@ __get_sp_mut(const void* p)
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)