Skip to content

Commit

Permalink
protected visitation against spurious insertion sentinels
Browse files Browse the repository at this point in the history
  • Loading branch information
joaquintides committed Dec 27, 2023
1 parent 8365ccb commit d689613
Showing 1 changed file with 28 additions and 8 deletions.
36 changes: 28 additions & 8 deletions include/boost/unordered/detail/foa/concurrent_table.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1177,7 +1177,7 @@ class concurrent_table:
do{
auto n=unchecked_countr_zero(mask);
if(BOOST_LIKELY(
pg->is_occupied(n)&&bool(this->pred()(x,this->key_from(p[n]))))){
is_occupied(pg,n)&&bool(this->pred()(x,this->key_from(p[n]))))){
f(pg,n,p+n);
return 1;
}
Expand Down Expand Up @@ -1236,7 +1236,7 @@ class concurrent_table:
do{
auto n=unchecked_countr_zero(mask);
if(BOOST_LIKELY(
pg->is_occupied(n)&&
is_occupied(pg,n)&&
bool(this->pred()(*it,this->key_from(p[n]))))){
f(cast_for(access_mode,type_policy::value_from(p[n])));
++res;
Expand Down Expand Up @@ -1579,23 +1579,43 @@ class concurrent_table:
}
}

/* check occupation with previous unsynced match */

static bool is_occupied(group_type* pg,std::size_t pos)
{
return is_occupied(
std::integral_constant<bool,group_type::regular_layout>{},pg,pos);
}

static bool is_occupied(std::true_type,group_type* pg,std::size_t pos)
{
/* regular layout, almost-latch-free insertion -> possible reserved slot */
return reinterpret_cast<std::atomic<unsigned char>*>(pg)[pos]>1;
}

static bool is_occupied(std::false_type,group_type* pg,std::size_t pos)
{
/* non-regular layout, latched insertion -> no reserved slots */
return pg->is_occupied(pos);
}

/* check occupation with previous synced match */

static bool is_really_occupied(group_type* pg,std::size_t pos)
{
return is_really_occupied(
std::integral_constant<bool,group_type::regular_layout>{},pg,pos);
}

static bool is_really_occupied(
/* regular layout, almost-latch-free insertion -> spurious non-zeros */
std::true_type,group_type* pg,std::size_t pos)
static bool is_really_occupied(std::true_type,group_type* pg,std::size_t pos)
{
/* regular layout, almost-latch-free insertion -> possible reserved slot */
return reinterpret_cast<std::atomic<unsigned char>*>(pg)[pos]>1;
}

static bool is_really_occupied(
/* non-regular layout, latched insertion -> no false positives */
std::false_type,group_type*,std::size_t)
static bool is_really_occupied(std::false_type,group_type*,std::size_t)
{
/* non-regular layout, latched insertion -> no false positives */
return true;
}

Expand Down

0 comments on commit d689613

Please sign in to comment.