[PATCH] D45196: [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions.

2018-04-16 Thread Eli Friedman via Phabricator via cfe-commits
efriedma closed this revision.
efriedma added a comment.

https://reviews.llvm.org/rL330162


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D45196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45196: [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions.

2018-04-14 Thread Saleem Abdulrasool via Phabricator via cfe-commits
compnerd accepted this revision.
compnerd added a comment.
This revision is now accepted and ready to land.

I definitely like the clean up.  Not sure I understand the motivation for the 
`__libcpp_relaxed_store`, but I suppose thats because its a copy from libc++ 
where it may be more useful.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D45196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45196: [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions.

2018-04-09 Thread Eli Friedman via Phabricator via cfe-commits
efriedma added a comment.

Ping.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D45196



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D45196: [libc++abi] Replace __sync_* functions with __libcpp_atomic_* functions.

2018-04-02 Thread Eli Friedman via Phabricator via cfe-commits
efriedma created this revision.
efriedma added reviewers: EricWF, compnerd.

This is basically part 2 of r313694.

It's a little unfortunate that I had to copy-paste atomic_support.h, but I 
don't really see any alternative.

The refstring.h changes are the same as the libcxx changes in r313694.


Repository:
  rCXXA libc++abi

https://reviews.llvm.org/D45196

Files:
  src/cxa_default_handlers.cpp
  src/cxa_exception.cpp
  src/cxa_handlers.cpp
  src/include/atomic_support.h
  src/include/refstring.h

Index: src/include/refstring.h
===
--- src/include/refstring.h
+++ src/include/refstring.h
@@ -22,6 +22,7 @@
 #include 
 #include 
 #endif
+#include "atomic_support.h"
 
 _LIBCPP_BEGIN_NAMESPACE_STD
 
@@ -87,19 +88,19 @@
 : __imp_(s.__imp_)
 {
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 }
 
 inline
 __libcpp_refstring& __libcpp_refstring::operator=(__libcpp_refstring const& s) _NOEXCEPT {
 bool adjust_old_count = __uses_refcount();
 struct _Rep_base *old_rep = rep_from_data(__imp_);
 __imp_ = s.__imp_;
 if (__uses_refcount())
-__sync_add_and_fetch(&rep_from_data(__imp_)->count, 1);
+__libcpp_atomic_add(&rep_from_data(__imp_)->count, 1);
 if (adjust_old_count)
 {
-if (__sync_add_and_fetch(&old_rep->count, count_t(-1)) < 0)
+if (__libcpp_atomic_add(&old_rep->count, count_t(-1)) < 0)
 {
 ::operator delete(old_rep);
 }
@@ -111,7 +112,7 @@
 __libcpp_refstring::~__libcpp_refstring() {
 if (__uses_refcount()) {
 _Rep_base* rep = rep_from_data(__imp_);
-if (__sync_add_and_fetch(&rep->count, count_t(-1)) < 0) {
+if (__libcpp_atomic_add(&rep->count, count_t(-1)) < 0) {
 ::operator delete(rep);
 }
 }
Index: src/include/atomic_support.h
===
--- /dev/null
+++ src/include/atomic_support.h
@@ -0,0 +1,181 @@
+//===--===
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===--===
+
+// FIXME: This file is copied from libcxx/src/include/atomic_support.h. Instead
+// of duplicating the file in libc++abi we should require that the libc++
+// sources are available when building libc++abi.
+
+#ifndef ATOMIC_SUPPORT_H
+#define ATOMIC_SUPPORT_H
+
+#include "__config"
+#include "memory" // for __libcpp_relaxed_load
+
+#if defined(__clang__) && __has_builtin(__atomic_load_n) \
+   && __has_builtin(__atomic_store_n)\
+   && __has_builtin(__atomic_add_fetch)  \
+   && __has_builtin(__atomic_exchange_n) \
+   && __has_builtin(__atomic_compare_exchange_n) \
+   && defined(__ATOMIC_RELAXED)  \
+   && defined(__ATOMIC_CONSUME)  \
+   && defined(__ATOMIC_ACQUIRE)  \
+   && defined(__ATOMIC_RELEASE)  \
+   && defined(__ATOMIC_ACQ_REL)  \
+   && defined(__ATOMIC_SEQ_CST)
+#   define _LIBCXXABI_HAS_ATOMIC_BUILTINS
+#elif !defined(__clang__) && defined(_GNUC_VER) && _GNUC_VER >= 407
+#   define _LIBCXXABI_HAS_ATOMIC_BUILTINS
+#endif
+
+#if !defined(_LIBCXXABI_HAS_ATOMIC_BUILTINS) && !defined(_LIBCXXABI_HAS_NO_THREADS)
+# if defined(_LIBCPP_WARNING)
+_LIBCPP_WARNING("Building libc++ without __atomic builtins is unsupported")
+# else
+#   warning Building libc++ without __atomic builtins is unsupported
+# endif
+#endif
+
+_LIBCPP_BEGIN_NAMESPACE_STD
+
+namespace {
+
+#if defined(_LIBCXXABI_HAS_ATOMIC_BUILTINS) && !defined(_LIBCXXABI_HAS_NO_THREADS)
+
+enum __libcpp_atomic_order {
+_AO_Relaxed = __ATOMIC_RELAXED,
+_AO_Consume = __ATOMIC_CONSUME,
+_AO_Acquire = __ATOMIC_ACQUIRE,
+_AO_Release = __ATOMIC_RELEASE,
+_AO_Acq_Rel = __ATOMIC_ACQ_REL,
+_AO_Seq = __ATOMIC_SEQ_CST
+};
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_atomic_store(_ValueType* __dest, _FromType __val,
+   int __order = _AO_Seq)
+{
+__atomic_store_n(__dest, __val, __order);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+void __libcpp_relaxed_store(_ValueType* __dest, _FromType __val)
+{
+__atomic_store_n(__dest, __val, _AO_Relaxed);
+}
+
+template 
+inline _LIBCPP_INLINE_VISIBILITY
+_ValueType __libcpp_atomic_load(_ValueType const* __val,
+int __order = _AO_Seq)
+{
+return __atomic_load_