[cfe-commits] [libcxx] r146865 - /libcxx/trunk/include/atomic

David Chisnall csdavec at swan.ac.uk
Mon Dec 19 03:44:21 PST 2011


Author: theraven
Date: Mon Dec 19 05:44:20 2011
New Revision: 146865

URL: http://llvm.org/viewvc/llvm-project?rev=146865&view=rev
Log:
Some fixes to <atomic> operations to explicitly use atomic types and operations.

The integral types now work with clang trunk (if you remove the guard), although we're still missing an intrinsic for initialising atomics (needed for C1x too).

Howard: Please review.


Modified:
    libcxx/trunk/include/atomic

Modified: libcxx/trunk/include/atomic
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/include/atomic?rev=146865&r1=146864&r2=146865&view=diff
==============================================================================
--- libcxx/trunk/include/atomic (original)
+++ libcxx/trunk/include/atomic Mon Dec 19 05:44:20 2011
@@ -555,7 +555,7 @@
 template <class _Tp, bool = is_integral<_Tp>::value && !is_same<_Tp, bool>::value>
 struct __atomic_base  // false
 {
-    _Tp __a_;
+    _Atomic(_Tp) __a_;
 
     _LIBCPP_INLINE_VISIBILITY
     bool is_lock_free() const volatile
@@ -621,7 +621,7 @@
     _LIBCPP_INLINE_VISIBILITY
     __atomic_base() {} // = default;
     _LIBCPP_INLINE_VISIBILITY
-    /*constexpr*/ __atomic_base(_Tp __d) : __a_(__d) {}
+    /*constexpr*/ __atomic_base(_Tp __d) { __atomic_store(&__a_, __d, memory_order_seq_cst); }
 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
     __atomic_base(const __atomic_base&) = delete;
     __atomic_base& operator=(const __atomic_base&) = delete;
@@ -820,7 +820,7 @@
 void
 atomic_init(volatile atomic<_Tp>* __o, _Tp __d)
 {
-    __o->__a_ = __d;
+    __atomic_store(&__o->__a_, __d, memory_order_seq_cst);
 }
 
 template <class _Tp>
@@ -828,7 +828,7 @@
 void
 atomic_init(atomic<_Tp>* __o, _Tp __d)
 {
-    __o->__a_ = __d;
+    __atomic_store(&__o->__a_, __d, memory_order_seq_cst);
 }
 
 // atomic_store
@@ -1348,7 +1348,7 @@
 
 typedef struct atomic_flag
 {
-    bool __a_;
+    _Atomic(bool) __a_;
 
     _LIBCPP_INLINE_VISIBILITY
     bool test_and_set(memory_order __m = memory_order_seq_cst) volatile
@@ -1366,7 +1366,7 @@
     _LIBCPP_INLINE_VISIBILITY
     atomic_flag() {} // = default;
     _LIBCPP_INLINE_VISIBILITY
-    atomic_flag(bool __b) : __a_(__b) {}
+    atomic_flag(bool __b) { __atomic_store(&__a_, __b, memory_order_seq_cst); }
 
 #ifndef _LIBCPP_HAS_NO_DELETED_FUNCTIONS
     atomic_flag(const atomic_flag&) = delete;





More information about the cfe-commits mailing list