From 2e447692473d0c8ec86848ad2f597ef30a0208d1 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Sat, 18 Mar 2023 11:56:14 +0100 Subject: [PATCH] added preliminary version of non-embedded group_access --- .../unordered/detail/foa/concurrent_table.hpp | 85 ++++++++++++++++++- include/boost/unordered/detail/foa/core.hpp | 11 ++- include/boost/unordered/detail/foa/table.hpp | 3 +- 3 files changed, 92 insertions(+), 7 deletions(-) diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index 4698ab87..3aba4a54 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -182,13 +182,70 @@ struct concurrent_group:Group,group_access }; }; +template +struct concurrent_table_arrays:table_arrays +{ + using super=table_arrays; + + template + static concurrent_table_arrays new_(Allocator& al,std::size_t n) + { + concurrent_table_arrays arrays={super::new_(al,n),nullptr}; + //if(arrays.elements){ + using access_alloc= + typename boost::allocator_rebind::type; + using access_traits=boost::allocator_traits; + using pointer=typename access_traits::pointer; + using pointer_traits=boost::pointer_traits; + + // TODO: protect with BOOST_TRY + auto aal=access_alloc(al); + arrays.group_accesses=boost::to_address( + access_traits::allocate(aal,arrays.groups_size_mask+1)); + + for(std::size_t n=0;n + static void delete_(Allocator& al,concurrent_table_arrays& arrays)noexcept + { + //if(arrays.elements){ + using access_alloc= + typename boost::allocator_rebind::type; + using access_traits=boost::allocator_traits; + using pointer=typename access_traits::pointer; + using pointer_traits=boost::pointer_traits; + + auto aal=access_alloc(al); + access_traits::deallocate( + aal,pointer_traits::pointer_to(*arrays.group_accesses), + arrays.groups_size_mask+1); + //} + } + + group_access *group_accesses; +}; + /* TODO: describe foa::concurrent_table. */ template using concurrent_table_core_impl=table_core< - TypePolicy,concurrent_group>,std::atomic_size_t, - Hash,Pred,Allocator>; + TypePolicy, + +#if defined(BOOST_UNORDERED_EMBEDDED_GROUP_ACCESS) + concurrent_group>, + table_arrays, +#else + group15, + concurrent_table_arrays, +#endif + + std::atomic_size_t,Hash,Pred,Allocator>; #include @@ -529,8 +586,15 @@ private: using shared_lock_guard=shared_lock; using exclusive_lock_guard=lock_guard; using exclusive_bilock_guard=scoped_bilock; + +#if defined(BOOST_UNORDERED_EMBEDDED_GROUP_ACCESS) using group_shared_lock_guard=typename group_type::shared_lock_guard; using group_exclusive_lock_guard=typename group_type::exclusive_lock_guard; +#else + using group_shared_lock_guard=typename group_access::shared_lock_guard; + using group_exclusive_lock_guard=typename group_access::exclusive_lock_guard; +#endif + concurrent_table(const concurrent_table& x,exclusive_lock_guard): super{x}{} @@ -562,6 +626,7 @@ private: return {x.mutexes,y.mutexes}; } +#if defined(BOOST_UNORDERED_EMBEDDED_GROUP_ACCESS) group_shared_lock_guard shared_access(std::size_t pos)const { return this->arrays.groups[pos].shared_access(); @@ -576,6 +641,22 @@ private: { return this->arrays.groups[pos].insert_counter(); } +#else + group_shared_lock_guard shared_access(std::size_t pos)const + { + return this->arrays.group_accesses[pos].shared_access(); + } + + group_exclusive_lock_guard exclusive_access(std::size_t pos)const + { + return this->arrays.group_accesses[pos].exclusive_access(); + } + + std::atomic_uint32_t& insert_counter(std::size_t pos)const + { + return this->arrays.group_accesses[pos].insert_counter(); + } +#endif std::size_t unprotected_size()const { diff --git a/include/boost/unordered/detail/foa/core.hpp b/include/boost/unordered/detail/foa/core.hpp index 324b24c2..0b67911d 100644 --- a/include/boost/unordered/detail/foa/core.hpp +++ b/include/boost/unordered/detail/foa/core.hpp @@ -1134,8 +1134,8 @@ alloc_make_insert_type(const Allocator& al,Args&&... args) #endif template< - typename TypePolicy,typename Group,typename SizeImpl, - typename Hash,typename Pred,typename Allocator + typename TypePolicy,typename Group,template class Arrays, + typename SizeImpl,typename Hash,typename Pred,typename Allocator > class @@ -1158,7 +1158,7 @@ public: >::type; using alloc_traits=boost::allocator_traits; using element_type=typename type_policy::element_type; - using arrays_type=table_arrays; + using arrays_type=Arrays; using key_type=typename type_policy::key_type; using init_type=typename type_policy::init_type; @@ -1646,7 +1646,10 @@ public: SizeImpl size_; private: - template + template< + typename,typename,template class, + typename,typename,typename,typename + > friend class table_core; using hash_base=empty_value; diff --git a/include/boost/unordered/detail/foa/table.hpp b/include/boost/unordered/detail/foa/table.hpp index 750e2db8..1cc23154 100644 --- a/include/boost/unordered/detail/foa/table.hpp +++ b/include/boost/unordered/detail/foa/table.hpp @@ -218,7 +218,8 @@ private: template using table_core_impl= - table_core,std::size_t,Hash,Pred,Allocator>; + table_core,table_arrays, + std::size_t,Hash,Pred,Allocator>; #include