From 3de21a474c5667cc4fb4abef4bde9f6f6ba30a4c Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sun, 9 Jul 2023 20:01:24 +0200 Subject: [PATCH] used shared group access for visitation functions taking its arg as a cref --- .../unordered/detail/foa/concurrent_table.hpp | 41 +++++++++++++------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index 0f1f1145..c83670d4 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -17,10 +17,13 @@ #include #include #include +#include +#include #include #include #include #include +#include #include #include #include @@ -485,7 +488,7 @@ public: template BOOST_FORCEINLINE std::size_t visit(const Key& x,F&& f) { - return visit_impl(group_exclusive{},x,std::forward(f)); + return visit_impl(group_access_for{},x,std::forward(f)); } template @@ -502,7 +505,7 @@ public: template std::size_t visit_all(F&& f) { - return visit_all_impl(group_exclusive{},std::forward(f)); + return visit_all_impl(group_access_for{},std::forward(f)); } template std::size_t visit_all(F&& f)const @@ -520,7 +523,7 @@ public: void visit_all(ExecutionPolicy&& policy,F&& f) { visit_all_impl( - group_exclusive{}, + group_access_for{}, std::forward(policy),std::forward(f)); } @@ -582,7 +585,7 @@ public: BOOST_FORCEINLINE bool try_emplace_or_visit(Key&& x,Args&&... args) { return emplace_or_visit_flast( - group_exclusive{}, + group_access_for_last_of{}, try_emplace_args_t{},std::forward(x),std::forward(args)...); } @@ -598,7 +601,7 @@ public: BOOST_FORCEINLINE bool emplace_or_visit(Args&&... args) { return construct_and_emplace_or_visit_flast( - group_exclusive{},std::forward(args)...); + group_access_for_last_of{},std::forward(args)...); } template @@ -611,7 +614,7 @@ public: template BOOST_FORCEINLINE bool insert_or_visit(const init_type& x,F&& f) { - return emplace_or_visit_impl(group_exclusive{},std::forward(f),x); + return emplace_or_visit_impl(group_access_for{},std::forward(f),x); } template @@ -624,7 +627,7 @@ public: BOOST_FORCEINLINE bool insert_or_visit(init_type&& x,F&& f) { return emplace_or_visit_impl( - group_exclusive{},std::forward(f),std::move(x)); + group_access_for{},std::forward(f),std::move(x)); } template @@ -640,7 +643,7 @@ public: BOOST_FORCEINLINE auto insert_or_visit(const Value& x,F&& f) ->enable_if_is_value_type { - return emplace_or_visit_impl(group_exclusive{},std::forward(f),x); + return emplace_or_visit_impl(group_access_for{},std::forward(f),x); } template @@ -655,7 +658,7 @@ public: ->enable_if_is_value_type { return emplace_or_visit_impl( - group_exclusive{},std::forward(f),std::move(x)); + group_access_for{},std::forward(f),std::move(x)); } template @@ -683,7 +686,7 @@ public: group_exclusive{},x,this->position_for(hash),hash, [&,this](group_type* pg,unsigned int n,element_type* p) { - if(f(cast_for(group_exclusive{},type_policy::value_from(*p)))){ + if(f(cast_for(group_access_for{},type_policy::value_from(*p)))){ super::erase(pg,n,p); res=1; } @@ -699,7 +702,7 @@ public: for_all_elements( group_exclusive{}, [&,this](group_type* pg,unsigned int n,element_type* p){ - if(f(cast_for(group_exclusive{},type_policy::value_from(*p)))){ + if(f(cast_for(group_access_for{},type_policy::value_from(*p)))){ super::erase(pg,n,p); ++res; } @@ -716,7 +719,7 @@ public: for_all_elements( group_exclusive{},std::forward(policy), [&,this](group_type* pg,unsigned int n,element_type* p){ - if(f(cast_for(group_exclusive{},type_policy::value_from(*p)))){ + if(f(cast_for(group_access_for{},type_policy::value_from(*p)))){ super::erase(pg,n,p); } }); @@ -886,6 +889,20 @@ private: using group_shared=std::false_type; using group_exclusive=std::true_type; + template + using group_access_for=typename std::conditional< + takes_arg_as_const_reference< + typename std::remove_cv::type>::type, + value_type + >::value, + group_shared, + group_exclusive + >::type; + + template + using group_access_for_last_of= + group_access_for>>; + inline group_shared_lock_guard access(group_shared,std::size_t pos)const { return this->arrays.group_accesses[pos].shared_access();