From b22c09700dedc20fef0cc6a592cfa603f3af7404 Mon Sep 17 00:00:00 2001 From: joaquintides Date: Mon, 12 Feb 2024 13:41:20 +0100 Subject: [PATCH] fixed erase_if on sentinels, implemented one-access non-constant visitation --- .../unordered/detail/foa/concurrent_table.hpp | 47 +++++++++++++------ 1 file changed, 33 insertions(+), 14 deletions(-) diff --git a/include/boost/unordered/detail/foa/concurrent_table.hpp b/include/boost/unordered/detail/foa/concurrent_table.hpp index 0b478063..28b338e1 100644 --- a/include/boost/unordered/detail/foa/concurrent_table.hpp +++ b/include/boost/unordered/detail/foa/concurrent_table.hpp @@ -553,7 +553,7 @@ public: #if defined(BOOST_UNORDERED_LATCH_FREE) ~concurrent_table(){ std::cout - <<"version: 2024/02/12 12:00; " + <<"version: 2024/02/12 13:40; " <<"lf: "<<(double)size()/capacity()<<"; " <<"size: "<reset(n); auto pc=reinterpret_cast*>(pg)+n; - if(pc->exchange(0)!=0){ + auto c=pc->load(std::memory_order_relaxed); + if(c>1&&pc->compare_exchange_strong(c,0,std::memory_order_acq_rel)){ auto& sc=local_size_ctrl(); sc.size.fetch_sub(1,std::memory_order_relaxed); sc.mcos.fetch_add( @@ -1313,7 +1314,7 @@ private: BOOST_FORCEINLINE bool save_access(std::size_t pos,boost::uint32_t n,F f)const { auto& acnt=access_counter(pos); - if(!acnt.compare_exchange_strong(n,n+1,std::memory_order_release)){ + if(!acnt.compare_exchange_strong(n,n+1,std::memory_order_acq_rel)){ return false; } std::atomic_thread_fence(std::memory_order_release); @@ -1354,20 +1355,38 @@ private: BOOST_UNORDERED_PREFETCH_ELEMENTS(p,N); do{ auto n=unchecked_countr_zero(mask); - if(BOOST_LIKELY(pg->is_occupied(n))){ - auto [e,acnt]=load_access(pos,[&]{return *(p+n);}); - if(BOOST_LIKELY(this->pred()(x,this->key_from(e)))){ - if constexpr(std::is_same::value){ - // ALTERNATIVE: offline f(pg,n,&e) +#if 0 + auto [e,acnt]=load_access(pos,[&]{return *(p+n);}); + if(BOOST_LIKELY(this->pred()(x,this->key_from(e)))){ + if constexpr(std::is_same::value){ + // ALTERNATIVE: offline f(pg,n,&e) - if(!save_access(pos,acnt,[&]{f(pg,n,p+n);}))goto startover; - return 1; - }else{ - f(pg,n,&e); - return 1; - } + if(!save_access(pos,acnt,[&]{f(pg,n,p+n);}))goto startover; + return 1; + }else{ + f(pg,n,&e); + return 1; } } +#else + if constexpr(std::is_same::value){ + bool res=false; + save_access(pos,[&]{ + if(BOOST_LIKELY(this->pred()(x,this->key_from(p[n])))){ + f(pg,n,p+n); + res=true; + } + }); + if(res)return 1; + } + else{ + auto [e,acnt]=load_access(pos,[&]{return *(p+n);}); + if(BOOST_LIKELY(this->pred()(x,this->key_from(e)))){ + f(pg,n,&e); + return 1; + } + } +#endif mask&=mask-1; }while(mask); }