+2012-02-10 Benjamin Kosnik <bkoz@redhat.com>
+ Jonathan Wakely <jwakely.gcc@gmail.com>
+
+ PR libstdc++/51798 continued.
+ * acinclude.m4 (GLIBCXX_ENABLE_ATOMIC_BUILTINS): Use __atomic_*
+ builtins instead of __sync_* builtins for atomic functionality.
+ * include/bits/shared_ptr_base.h: Same.
+ * include/parallel/compatibility.h: Same.
+ * include/profile/impl/profiler_state.h: Same.
+ * include/tr1/shared_ptr.h: Same.
+ * libsupc++/eh_ptr.cc: Same.
+ * libsupc++/eh_throw.cc: Same.
+ * libsupc++/eh_tm.cc: Same.
+ * libsupc++/guard.cc: Same.
+ * configure: Regenerated.
+ * testsuite/20_util/shared_ptr/cons/43820_neg.cc: Adjust line numbers.
+ * testsuite/tr1/2_general_utilities/shared_ptr/cons/43820_neg.cc: Same.
+
2012-02-10 Rainer Orth <ro@CeBiTec.Uni-Bielefeld.DE>
PR libstdc++/51296
dnl
dnl Check for atomic builtins.
dnl See:
-dnl http://gcc.gnu.org/onlinedocs/gcc/Atomic-Builtins.html#Atomic-Builtins
+dnl http://gcc.gnu.org/onlinedocs/gcc/_005f_005fatomic-Builtins.html
dnl
dnl This checks to see if the host supports the compiler-generated
dnl builtins for atomic operations for various integral sizes. Note, this
[typedef bool atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();],
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+ ],
[glibcxx_cv_atomic_bool=yes],
[glibcxx_cv_atomic_bool=no])
])
[typedef short atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();],
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+ ],
[glibcxx_cv_atomic_short=yes],
[glibcxx_cv_atomic_short=no])
])
[typedef int atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();],
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+ ],
[glibcxx_cv_atomic_int=yes],
[glibcxx_cv_atomic_int=no])
])
[typedef long long atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();],
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+ ],
[glibcxx_cv_atomic_long_long=yes],
[glibcxx_cv_atomic_long_long=no])
])
typedef bool atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
typedef short atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
typedef int atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
typedef long long atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
CXXFLAGS="$old_CXXFLAGS"
AC_LANG_RESTORE
- # Set atomicity_dir to builtins if either of above tests pass.
- if test $glibcxx_cv_atomic_int = yes || test $glibcxx_cv_atomic_bool = yes ; then
+ # Set atomicity_dir to builtins if all of above tests pass.
+ if test $glibcxx_cv_atomic_bool = yes \
+ && test $glibcxx_cv_atomic_short = yes \
+ && test $glibcxx_cv_atomic_int = yes \
+ && test $glibcxx_cv_atomic_long_long = yes ; then
AC_DEFINE(_GLIBCXX_ATOMIC_BUILTINS, 1,
[Define if the compiler supports C++11 atomics.])
atomicity_dir=cpu/generic/atomicity_builtins
typedef bool atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
;
return 0;
}
typedef short atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
;
return 0;
}
typedef int atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
;
return 0;
}
typedef long long atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
;
return 0;
}
# Fake what AC_TRY_COMPILE does.
cat > conftest.$ac_ext << EOF
-#line 15284 "configure"
+#line 15288 "configure"
int main()
{
typedef bool atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 15318 "configure"
+#line 15323 "configure"
int main()
{
typedef short atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 15352 "configure"
+#line 15358 "configure"
int main()
{
// NB: _Atomic_word not necessarily int.
typedef int atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 15387 "configure"
+#line 15394 "configure"
int main()
{
typedef long long atomic_type;
atomic_type c1;
atomic_type c2;
- const atomic_type c3(0);
- __sync_fetch_and_add(&c1, c2);
- __sync_val_compare_and_swap(&c1, c3, c2);
- __sync_lock_test_and_set(&c1, c3);
- __sync_lock_release(&c1);
- __sync_synchronize();
+ atomic_type c3(0);
+ __atomic_fetch_add(&c1, c2, __ATOMIC_RELAXED);
+ __atomic_compare_exchange_n(&c1, &c2, c3, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ __atomic_test_and_set(&c1, __ATOMIC_RELAXED);
+ __atomic_load_n(&c1, __ATOMIC_RELAXED);
+
return 0;
}
EOF
ac_compiler_gnu=$ac_cv_c_compiler_gnu
- # Set atomicity_dir to builtins if either of above tests pass.
- if test $glibcxx_cv_atomic_int = yes || test $glibcxx_cv_atomic_bool = yes ; then
+ # Set atomicity_dir to builtins if all of above tests pass.
+ if test $glibcxx_cv_atomic_bool = yes \
+ && test $glibcxx_cv_atomic_short = yes \
+ && test $glibcxx_cv_atomic_int = yes \
+ && test $glibcxx_cv_atomic_long_long = yes ; then
$as_echo "#define _GLIBCXX_ATOMIC_BUILTINS 1" >>confdefs.h
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 15463 "configure"
+#line 15474 "configure"
int main()
{
_Decimal32 d1;
# unnecessary for this test.
cat > conftest.$ac_ext << EOF
-#line 15505 "configure"
+#line 15516 "configure"
template<typename T1, typename T2>
struct same
{ typedef T2 type; };
rm -f conftest*
cat > conftest.$ac_ext << EOF
-#line 15539 "configure"
+#line 15550 "configure"
template<typename T1, typename T2>
struct same
{ typedef T2 type; };
// shared_ptr and weak_ptr implementation details -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
+// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
// No memory barrier is used here so there is no synchronization
// with other threads.
- return const_cast<const volatile _Atomic_word&>(_M_use_count);
+ return __atomic_load_n(&_M_use_count, __ATOMIC_RELAXED);
}
private:
// Replace the current counter value with the old value + 1, as
// long as it's not changed meanwhile.
}
- while (!__sync_bool_compare_and_swap(&_M_use_count, __count,
- __count + 1));
+ while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
+ true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED));
}
// -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
return _InterlockedExchangeAdd(reinterpret_cast<volatile long*>(__ptr),
__addend);
#elif defined(__GNUC__)
- return __sync_fetch_and_add(__ptr, __addend);
+ return __atomic_fetch_add(__ptr, __addend, __ATOMIC_ACQ_REL);
#elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int32_t __before, __after;
do
return _InterlockedExchangeAdd64(__ptr, __addend);
#endif
#elif defined(__GNUC__) && defined(__x86_64)
- return __sync_fetch_and_add(__ptr, __addend);
+ return __atomic_fetch_add(__ptr, __addend, __ATOMIC_ACQ_REL);
#elif defined(__GNUC__) && defined(__i386) && \
(defined(__i686) || defined(__pentium4) || defined(__athlon) \
|| defined(__k8) || defined(__core2))
- return __sync_fetch_and_add(__ptr, __addend);
+ return __atomic_fetch_add(__ptr, __addend, __ATOMIC_ACQ_REL);
#elif defined(__SUNPRO_CC) && defined(__sparc)
volatile int64_t __before, __after;
do
__replacement, __comparand)
== __comparand;
#elif defined(__GNUC__)
- return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement);
+ return __atomic_compare_exchange_n(__ptr, &__comparand, __replacement, true,
+ __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
#elif defined(__SUNPRO_CC) && defined(__sparc)
return atomic_cas_32((volatile unsigned int*)__ptr, __comparand,
__replacement) == __comparand;
#endif
#elif defined(__GNUC__) && defined(__x86_64)
- return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement);
+ return __atomic_compare_exchange_n(__ptr, &__comparand, __replacement, true,
+ __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
#elif defined(__GNUC__) && defined(__i386) && \
(defined(__i686) || defined(__pentium4) || defined(__athlon) \
|| defined(__k8) || defined(__core2))
- return __sync_bool_compare_and_swap(__ptr, __comparand, __replacement);
+ return __atomic_compare_exchange_n(__ptr, &__comparand, __replacement, true,
+ __ATOMIC_ACQ_REL, __ATOMIC_RELAXED);
#elif defined(__SUNPRO_CC) && defined(__sparc)
return atomic_cas_64((volatile unsigned long long*)__ptr,
__comparand, __replacement) == __comparand;
// -*- C++ -*-
//
-// Copyright (C) 2009, 2010 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2010, 2012 Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the terms
inline bool
__turn(__state_type __s)
- { return (_GLIBCXX_PROFILE_DATA(__state)
- == __sync_val_compare_and_swap(&_GLIBCXX_PROFILE_DATA(__state),
- __INVALID, __s)); }
+ {
+ __state_type inv(__INVALID);
+ return __atomic_compare_exchange_n(&_GLIBCXX_PROFILE_DATA(__state),
+ &inv, __s, true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED);
+ }
inline bool
__turn_on()
// <tr1/shared_ptr.h> -*- C++ -*-
-// Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012
+// Free Software Foundation, Inc.
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
// Replace the current counter value with the old value + 1, as
// long as it's not changed meanwhile.
}
- while (!__sync_bool_compare_and_swap(&_M_use_count, __count,
- __count + 1));
- }
+ while (!__atomic_compare_exchange_n(&_M_use_count, &__count, __count + 1,
+ true, __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED));
+ }
template<typename _Ptr, typename _Deleter, _Lock_policy _Lp>
class _Sp_counted_base_impl
// -*- C++ -*- Implement the members of exception_ptr.
-// Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
{
__cxa_refcounted_exception *eh =
__get_refcounted_exception_header_from_obj (_M_exception_object);
- __sync_add_and_fetch (&eh->referenceCount, 1);
+ __atomic_add_fetch (&eh->referenceCount, 1, __ATOMIC_ACQ_REL);
}
}
{
__cxa_refcounted_exception *eh =
__get_refcounted_exception_header_from_obj (_M_exception_object);
- if (__sync_sub_and_fetch (&eh->referenceCount, 1) == 0)
+ if (__atomic_sub_fetch (&eh->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
{
if (eh->exc.exceptionDestructor)
eh->exc.exceptionDestructor (_M_exception_object);
__cxa_free_dependent_exception (dep);
- if (__sync_sub_and_fetch (&header->referenceCount, 1) == 0)
+ if (__atomic_sub_fetch (&header->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
{
if (header->exc.exceptionDestructor)
header->exc.exceptionDestructor (header + 1);
__cxa_dependent_exception *dep = __cxa_allocate_dependent_exception ();
dep->primaryException = obj;
- __sync_add_and_fetch (&eh->referenceCount, 1);
+ __atomic_add_fetch (&eh->referenceCount, 1, __ATOMIC_ACQ_REL);
dep->unexpectedHandler = __unexpected_handler;
dep->terminateHandler = __terminate_handler;
// -*- C++ -*- Exception handling routines for throwing.
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
-// 2011 Free Software Foundation, Inc.
+// 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
__terminate (header->exc.terminateHandler);
#if ATOMIC_INT_LOCK_FREE > 1
- if (__sync_sub_and_fetch (&header->referenceCount, 1) == 0)
+ if (__atomic_sub_fetch (&header->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
{
#endif
if (header->exc.exceptionDestructor)
// -*- C++ -*- Exception handling routines for Transactional Memory.
-// Copyright (C) 2009, 2011 Free Software Foundation, Inc.
+// Copyright (C) 2009, 2011, 2012 Free Software Foundation, Inc.
//
// This file is part of GCC.
//
}
#if __GCC_ATOMIC_INT_LOCK_FREE > 1
- if (__sync_sub_and_fetch (&h->referenceCount, 1) == 0)
+ if (__atomic_sub_fetch (&h->referenceCount, 1, __ATOMIC_ACQ_REL) == 0)
#endif
__cxa_free_exception (h + 1);
}
-// Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010, 2011
+// Copyright (C) 2002, 2004, 2006, 2008, 2009, 2010, 2011, 2012
// Free Software Foundation, Inc.
//
// This file is part of GCC.
return 0;
# ifdef _GLIBCXX_USE_FUTEX
- // If __sync_* and futex syscall are supported, don't use any global
+ // If __atomic_* and futex syscall are supported, don't use any global
// mutex.
if (__gthread_active_p ())
{
int *gi = (int *) (void *) g;
+ int expected(0);
const int guard_bit = _GLIBCXX_GUARD_BIT;
const int pending_bit = _GLIBCXX_GUARD_PENDING_BIT;
const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
while (1)
{
- int old = __sync_val_compare_and_swap (gi, 0, pending_bit);
- if (old == 0)
- return 1; // This thread should do the initialization.
-
- if (old == guard_bit)
- return 0; // Already initialized.
-
- if (old == pending_bit)
+ if (__atomic_compare_exchange_n(gi, &expected, pending_bit, true,
+ __ATOMIC_ACQ_REL, __ATOMIC_RELAXED))
{
- int newv = old | waiting_bit;
- if (__sync_val_compare_and_swap (gi, old, newv) != old)
- continue;
-
- old = newv;
+ // This thread should do the initialization.
+ return 1;
}
-
- syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAIT, old, 0);
+
+ if (expected == guard_bit)
+ {
+ // Already initialized.
+ return 0;
+ }
+ if (expected == pending_bit)
+ {
+ int newv = expected | waiting_bit;
+ if (!__atomic_compare_exchange_n(gi, &expected, newv, true,
+ __ATOMIC_ACQ_REL,
+ __ATOMIC_RELAXED))
+ continue;
+
+ expected = newv;
+ }
+
+ syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAIT, expected, 0);
}
}
# else
void __cxa_guard_abort (__guard *g) throw ()
{
#ifdef _GLIBCXX_USE_FUTEX
- // If __sync_* and futex syscall are supported, don't use any global
+ // If __atomic_* and futex syscall are supported, don't use any global
// mutex.
if (__gthread_active_p ())
{
int *gi = (int *) (void *) g;
const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
- int old = __sync_lock_test_and_set (gi, 0);
+ int old = __atomic_exchange_n (gi, 0, __ATOMIC_ACQ_REL);
if ((old & waiting_bit) != 0)
syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAKE, INT_MAX);
void __cxa_guard_release (__guard *g) throw ()
{
#ifdef _GLIBCXX_USE_FUTEX
- // If __sync_* and futex syscall are supported, don't use any global
+ // If __atomic_* and futex syscall are supported, don't use any global
// mutex.
if (__gthread_active_p ())
{
int *gi = (int *) (void *) g;
const int guard_bit = _GLIBCXX_GUARD_BIT;
const int waiting_bit = _GLIBCXX_GUARD_WAITING_BIT;
- int old = __sync_lock_test_and_set (gi, guard_bit);
+ int old = __atomic_exchange_n (gi, guard_bit, __ATOMIC_ACQ_REL);
if ((old & waiting_bit) != 0)
syscall (SYS_futex, gi, _GLIBCXX_FUTEX_WAKE, INT_MAX);
// { dg-options "-std=gnu++0x" }
// { dg-do compile }
-// Copyright (C) 2010, 2011 Free Software Foundation
+// Copyright (C) 2010, 2011, 2012 Free Software Foundation
//
// This file is part of the GNU ISO C++ Library. This library is free
// software; you can redistribute it and/or modify it under the
{
X* px = 0;
std::shared_ptr<X> p1(px); // { dg-error "here" }
- // { dg-error "incomplete" "" { target *-*-* } 771 }
+ // { dg-error "incomplete" "" { target *-*-* } 773 }
std::shared_ptr<X> p9(ap()); // { dg-error "here" }
- // { dg-error "incomplete" "" { target *-*-* } 865 }
+ // { dg-error "incomplete" "" { target *-*-* } 867 }
}
{
X* px = 0;
std::tr1::shared_ptr<X> p1(px); // { dg-error "here" }
- // { dg-error "incomplete" "" { target *-*-* } 563 }
+ // { dg-error "incomplete" "" { target *-*-* } 565 }
std::tr1::shared_ptr<X> p9(ap()); // { dg-error "here" }
- // { dg-error "incomplete" "" { target *-*-* } 602 }
+ // { dg-error "incomplete" "" { target *-*-* } 604 }
}