From 56a165ecdccf7828d9ba94e8faa51212f85f892e Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Fri, 24 Aug 2018 02:30:38 +0300 Subject: [PATCH] Rearrange atomic operator internals --- Utilities/Atomic.h | 28 ++++++++++++++-------------- Utilities/bit_set.h | 27 ++++++++++++++------------- Utilities/types.h | 39 --------------------------------------- 3 files changed, 28 insertions(+), 66 deletions(-) diff --git a/Utilities/Atomic.h b/Utilities/Atomic.h index ffc8ef15b0..9e4709c323 100644 --- a/Utilities/Atomic.h +++ b/Utilities/Atomic.h @@ -3,7 +3,7 @@ #include "types.h" // Helper class, provides access to compiler-specific atomic intrinsics -template +template struct atomic_storage { static_assert(sizeof(T) <= 16 && sizeof(T) == alignof(T), "atomic_storage<> error: invalid type"); @@ -562,7 +562,7 @@ struct atomic_storage : atomic_storage // TODO }; -template +template struct atomic_add { auto operator()(T1& lhs, const T2& rhs) const @@ -579,7 +579,7 @@ struct atomic_add::value && std::i static constexpr auto atomic_op = &atomic_storage::add_fetch; }; -template +template struct atomic_sub { auto operator()(T1& lhs, const T2& rhs) const @@ -596,7 +596,7 @@ struct atomic_sub::value && std::i static constexpr auto atomic_op = &atomic_storage::sub_fetch; }; -template +template struct atomic_pre_inc { auto operator()(T& v) const @@ -611,7 +611,7 @@ struct atomic_pre_inc::value>> static constexpr auto atomic_op = &atomic_storage::inc_fetch; }; -template +template struct atomic_post_inc { auto operator()(T& v) const @@ -626,7 +626,7 @@ struct atomic_post_inc::value>> static constexpr auto atomic_op = &atomic_storage::fetch_inc; }; -template +template struct atomic_pre_dec { auto operator()(T& v) const @@ -641,7 +641,7 @@ struct atomic_pre_dec::value>> static constexpr auto atomic_op = &atomic_storage::dec_fetch; }; -template +template struct atomic_post_dec { auto operator()(T& v) const @@ -656,7 +656,7 @@ struct atomic_post_dec::value>> static constexpr auto atomic_op = &atomic_storage::fetch_dec; }; -template +template struct atomic_and { auto operator()(T1& lhs, const T2& rhs) const @@ -673,7 +673,7 @@ struct atomic_and::value && std::i static constexpr auto atomic_op = &atomic_storage::and_fetch; }; -template +template struct atomic_or { auto operator()(T1& lhs, const T2& rhs) const @@ -690,7 +690,7 @@ struct atomic_or::value && std::is static constexpr auto atomic_op = &atomic_storage::or_fetch; }; -template +template struct atomic_xor { auto operator()(T1& lhs, const T2& rhs) const @@ -707,7 +707,7 @@ struct atomic_xor::value && std::i static constexpr auto atomic_op = &atomic_storage::xor_fetch; }; -template +template struct atomic_test_and_set { bool operator()(T1& lhs, const T2& rhs) const @@ -724,7 +724,7 @@ struct atomic_test_and_set::value static constexpr auto atomic_op = &atomic_storage::test_and_set; }; -template +template struct atomic_test_and_reset { bool operator()(T1& lhs, const T2& rhs) const @@ -741,7 +741,7 @@ struct atomic_test_and_reset::valu static constexpr auto atomic_op = &atomic_storage::test_and_reset; }; -template +template struct atomic_test_and_complement { bool operator()(T1& lhs, const T2& rhs) const @@ -916,7 +916,7 @@ public: { return fetch_op(atomic_add{}, rhs); } - + template type add_fetch(const T2& rhs) { diff --git a/Utilities/bit_set.h b/Utilities/bit_set.h index 8990169263..f37bde7b92 100644 --- a/Utilities/bit_set.h +++ b/Utilities/bit_set.h @@ -43,6 +43,7 @@ Intersection (&) and symmetric difference (^) is also available. */ #include "types.h" +#include "Atomic.h" // Helper template template @@ -368,7 +369,7 @@ struct atomic_xor -struct atomic_add> +struct atomic_add::value>> { using under = std::underlying_type_t; @@ -389,7 +390,7 @@ struct atomic_add> }; template -struct atomic_sub> +struct atomic_sub::value>> { using under = std::underlying_type_t; @@ -410,7 +411,7 @@ struct atomic_sub> }; template -struct atomic_and> +struct atomic_and::value>> { using under = std::underlying_type_t; @@ -431,7 +432,7 @@ struct atomic_and> }; template -struct atomic_xor> +struct atomic_xor::value>> { using under = std::underlying_type_t; @@ -497,7 +498,7 @@ struct atomic_test_and_complement -struct atomic_test_and_set> +struct atomic_test_and_set::value>> { using under = std::underlying_type_t; @@ -512,7 +513,7 @@ struct atomic_test_and_set> }; template -struct atomic_test_and_reset> +struct atomic_test_and_reset::value>> { using under = std::underlying_type_t; @@ -527,7 +528,7 @@ struct atomic_test_and_reset> }; template -struct atomic_test_and_complement> +struct atomic_test_and_complement::value>> { using under = std::underlying_type_t; @@ -624,7 +625,7 @@ inline bool test_and_complement(T& lhs, T rhs) } template -struct atomic_or::value>>> +struct atomic_or::value>> { using under = std::underlying_type_t; @@ -645,7 +646,7 @@ struct atomic_or -struct atomic_and::value>>> +struct atomic_and::value>> { using under = std::underlying_type_t; @@ -666,7 +667,7 @@ struct atomic_and -struct atomic_xor::value>>> +struct atomic_xor::value>> { using under = std::underlying_type_t; @@ -687,7 +688,7 @@ struct atomic_xor -struct atomic_test_and_set::value>>> +struct atomic_test_and_set::value>> { using under = std::underlying_type_t; @@ -702,7 +703,7 @@ struct atomic_test_and_set -struct atomic_test_and_reset::value>>> +struct atomic_test_and_reset::value>> { using under = std::underlying_type_t; @@ -717,7 +718,7 @@ struct atomic_test_and_reset -struct atomic_test_and_complement::value>>> +struct atomic_test_and_complement::value>> { using under = std::underlying_type_t; diff --git a/Utilities/types.h b/Utilities/types.h index 25508f9c06..34913bb0d8 100644 --- a/Utilities/types.h +++ b/Utilities/types.h @@ -114,45 +114,6 @@ struct se_storage; template class se_t; -template -struct atomic_storage; - -template -struct atomic_add; - -template -struct atomic_sub; - -template -struct atomic_and; - -template -struct atomic_or; - -template -struct atomic_xor; - -template -struct atomic_pre_inc; - -template -struct atomic_post_inc; - -template -struct atomic_pre_dec; - -template -struct atomic_post_dec; - -template -struct atomic_test_and_set; - -template -struct atomic_test_and_reset; - -template -struct atomic_test_and_complement; - template class atomic_t;