summaryrefslogtreecommitdiff
path: root/boost/atomic/detail/ops_gcc_sync.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'boost/atomic/detail/ops_gcc_sync.hpp')
-rw-r--r--boost/atomic/detail/ops_gcc_sync.hpp105
1 files changed, 26 insertions, 79 deletions
diff --git a/boost/atomic/detail/ops_gcc_sync.hpp b/boost/atomic/detail/ops_gcc_sync.hpp
index 2a075bcf9f..1597de852a 100644
--- a/boost/atomic/detail/ops_gcc_sync.hpp
+++ b/boost/atomic/detail/ops_gcc_sync.hpp
@@ -34,11 +34,12 @@ namespace detail {
struct gcc_sync_operations_base
{
+ static BOOST_CONSTEXPR_OR_CONST bool full_cas_based = false;
static BOOST_CONSTEXPR_OR_CONST bool is_always_lock_free = true;
static BOOST_FORCEINLINE void fence_before_store(memory_order order) BOOST_NOEXCEPT
{
- if ((order & memory_order_release) != 0)
+ if ((static_cast< unsigned int >(order) & static_cast< unsigned int >(memory_order_release)) != 0u)
__sync_synchronize();
}
@@ -50,16 +51,20 @@ struct gcc_sync_operations_base
static BOOST_FORCEINLINE void fence_after_load(memory_order order) BOOST_NOEXCEPT
{
- if ((order & (memory_order_acquire | memory_order_consume)) != 0)
+ if ((static_cast< unsigned int >(order) & (static_cast< unsigned int >(memory_order_acquire) | static_cast< unsigned int >(memory_order_consume))) != 0u)
__sync_synchronize();
}
};
-template< typename T >
+template< std::size_t Size, bool Signed >
struct gcc_sync_operations :
public gcc_sync_operations_base
{
- typedef T storage_type;
+ typedef typename make_storage_type< Size >::type storage_type;
+ typedef typename make_storage_type< Size >::aligned aligned_storage_type;
+
+ static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = Size;
+ static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
static BOOST_FORCEINLINE void store(storage_type volatile& storage, storage_type v, memory_order order) BOOST_NOEXCEPT
{
@@ -90,7 +95,7 @@ struct gcc_sync_operations :
// GCC docs mention that not all architectures may support full exchange semantics for this intrinsic. However, GCC's implementation of
// std::atomic<> uses this intrinsic unconditionally. We do so as well. In case if some architectures actually don't support this, we can always
// add a check here and fall back to a CAS loop.
- if ((order & memory_order_release) != 0)
+ if ((static_cast< unsigned int >(order) & static_cast< unsigned int >(memory_order_release)) != 0u)
__sync_synchronize();
return __sync_lock_test_and_set(&storage, v);
}
@@ -135,7 +140,7 @@ struct gcc_sync_operations :
static BOOST_FORCEINLINE bool test_and_set(storage_type volatile& storage, memory_order order) BOOST_NOEXCEPT
{
- if ((order & memory_order_release) != 0)
+ if ((static_cast< unsigned int >(order) & static_cast< unsigned int >(memory_order_release)) != 0u)
__sync_synchronize();
return !!__sync_lock_test_and_set(&storage, 1);
}
@@ -152,35 +157,17 @@ struct gcc_sync_operations :
template< bool Signed >
struct operations< 1u, Signed > :
#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)
- public gcc_sync_operations< typename make_storage_type< 1u, Signed >::type >
+ public gcc_sync_operations< 1u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 2u, Signed >::type >, 1u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 2u, Signed >, 1u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 4u, Signed >::type >, 1u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 4u, Signed >, 1u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 8u, Signed >::type >, 1u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 8u, Signed >, 1u, Signed >
#else
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 16u, Signed >::type >, 1u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 16u, Signed >, 1u, Signed >
#endif
{
-#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_1)
- typedef typename make_storage_type< 1u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 1u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
- typedef typename make_storage_type< 2u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 2u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- typedef typename make_storage_type< 4u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 4u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 8u;
-#else
- typedef typename make_storage_type< 16u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 16u;
-#endif
-
- static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
};
#endif
@@ -188,30 +175,15 @@ struct operations< 1u, Signed > :
template< bool Signed >
struct operations< 2u, Signed > :
#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
- public gcc_sync_operations< typename make_storage_type< 2u, Signed >::type >
+ public gcc_sync_operations< 2u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 4u, Signed >::type >, 2u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 4u, Signed >, 2u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 8u, Signed >::type >, 2u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 8u, Signed >, 2u, Signed >
#else
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 16u, Signed >::type >, 2u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 16u, Signed >, 2u, Signed >
#endif
{
-#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_2)
- typedef typename make_storage_type< 2u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 2u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- typedef typename make_storage_type< 4u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 4u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 8u;
-#else
- typedef typename make_storage_type< 16u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 16u;
-#endif
-
- static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
};
#endif
@@ -219,25 +191,13 @@ struct operations< 2u, Signed > :
template< bool Signed >
struct operations< 4u, Signed > :
#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- public gcc_sync_operations< typename make_storage_type< 4u, Signed >::type >
+ public gcc_sync_operations< 4u, Signed >
#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 8u, Signed >::type >, 4u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 8u, Signed >, 4u, Signed >
#else
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 16u, Signed >::type >, 4u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 16u, Signed >, 4u, Signed >
#endif
{
-#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
- typedef typename make_storage_type< 4u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 4u;
-#elif defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 8u;
-#else
- typedef typename make_storage_type< 16u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 16u;
-#endif
-
- static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
};
#endif
@@ -245,32 +205,19 @@ struct operations< 4u, Signed > :
template< bool Signed >
struct operations< 8u, Signed > :
#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- public gcc_sync_operations< typename make_storage_type< 8u, Signed >::type >
+ public gcc_sync_operations< 8u, Signed >
#else
- public extending_cas_based_operations< gcc_sync_operations< typename make_storage_type< 16u, Signed >::type >, 8u, Signed >
+ public extending_cas_based_operations< gcc_sync_operations< 16u, Signed >, 8u, Signed >
#endif
{
-#if defined(__GCC_HAVE_SYNC_COMPARE_AND_SWAP_8)
- typedef typename make_storage_type< 8u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 8u;
-#else
- typedef typename make_storage_type< 16u, Signed >::aligned aligned_storage_type;
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 16u;
-#endif
-
- static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
};
#endif
#if BOOST_ATOMIC_INT128_LOCK_FREE > 0
template< bool Signed >
struct operations< 16u, Signed > :
- public gcc_sync_operations< typename make_storage_type< 16u, Signed >::type >
+ public gcc_sync_operations< 16u, Signed >
{
- typedef typename make_storage_type< 16u, Signed >::aligned aligned_storage_type;
-
- static BOOST_CONSTEXPR_OR_CONST std::size_t storage_size = 16u;
- static BOOST_CONSTEXPR_OR_CONST bool is_signed = Signed;
};
#endif