Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save eblot/44ddc4a45ffd4bf03795bb5fbeeb40fd to your computer and use it in GitHub Desktop.
Save eblot/44ddc4a45ffd4bf03795bb5fbeeb40fd to your computer and use it in GitHub Desktop.
Atomic w/ threadless bare metal (adapter from Yves Delley's)
diff --git a/libcxx/include/__config b/libcxx/include/__config
index 044cd0ceb00..f388afee43e 100644
--- a/libcxx/include/__config
+++ b/libcxx/include/__config
@@ -1204,14 +1204,13 @@ _LIBCPP_FUNC_VIS extern "C" void __sanitizer_annotate_contiguous_container(
#if (!defined(_LIBCPP_HAS_C_ATOMIC_IMP) && \
!defined(_LIBCPP_HAS_GCC_ATOMIC_IMP) && \
- !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP)) \
- || defined(_LIBCPP_HAS_NO_THREADS)
+ !defined(_LIBCPP_HAS_EXTERNAL_ATOMIC_IMP))
# define _LIBCPP_HAS_NO_ATOMIC_HEADER
#else
# ifndef _LIBCPP_ATOMIC_FLAG_TYPE
# define _LIBCPP_ATOMIC_FLAG_TYPE bool
# endif
-# ifdef _LIBCPP_FREESTANDING
+# if defined(_LIBCPP_FREESTANDING) || defined(_LIBCPP_HAS_NO_THREADS)
# define _LIBCPP_ATOMIC_ONLY_USE_BUILTINS
# endif
#endif
diff --git a/libcxx/include/atomic b/libcxx/include/atomic
index 6904dd40003..683019e6471 100644
--- a/libcxx/include/atomic
+++ b/libcxx/include/atomic
@@ -556,9 +556,6 @@ void atomic_signal_fence(memory_order m) noexcept;
#pragma GCC system_header
#endif
-#ifdef _LIBCPP_HAS_NO_THREADS
-# error <atomic> is not supported on this single threaded system
-#endif
#ifdef _LIBCPP_HAS_NO_ATOMIC_HEADER
# error <atomic> is not implemented
#endif
diff --git a/libcxx/src/memory.cpp b/libcxx/src/memory.cpp
index e89d94f27e4..27eeaf06333 100644
--- a/libcxx/src/memory.cpp
+++ b/libcxx/src/memory.cpp
@@ -134,7 +134,7 @@ __shared_weak_count::__get_deleter(const type_info&) const _NOEXCEPT
#endif // _LIBCPP_NO_RTTI
-#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] =
@@ -185,7 +185,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
declare_reachable(void*)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment