fixed reentrancy checking for scoped_bilock

This commit is contained in:
joaquintides
2023-07-24 19:44:09 +02:00
parent 948151bd7d
commit a3626b5095
2 changed files with 36 additions and 6 deletions

View File

@ -840,8 +840,7 @@ private:
using multimutex_type=multimutex<mutex_type,128>; // TODO: adapt 128 to the machine
using shared_lock_guard=reentrancy_checked<shared_lock<mutex_type>>;
using exclusive_lock_guard=reentrancy_checked<lock_guard<multimutex_type>>;
using exclusive_bilock_guard=
reentrancy_checked<reentrancy_checked<scoped_bilock<multimutex_type>>>;
using exclusive_bilock_guard=reentrancy_bichecked<scoped_bilock<multimutex_type>>;
using group_shared_lock_guard=typename group_access::shared_lock_guard;
using group_exclusive_lock_guard=typename group_access::exclusive_lock_guard;
using group_insert_counter_type=typename group_access::insert_counter_type;

View File

@ -56,10 +56,11 @@ class entry_trace
public:
entry_trace(const void* px_):px{px_}
{
BOOST_ASSERT(px!=nullptr);
BOOST_UNORDERED_REENTRANCY_CHECK_ASSERT_MSG(
!find(px),"reentrancy not allowed");
header()=this;
if(px){
BOOST_UNORDERED_REENTRANCY_CHECK_ASSERT_MSG(
!find(px),"reentrancy not allowed");
header()=this;
}
}
/* not used but VS in pre-C++17 mode needs to see it for RVO */
@ -111,6 +112,24 @@ struct reentrancy_checked
LockGuard lck;
};
template<typename LockGuard>
struct reentrancy_bichecked
{
template<typename... Args>
reentrancy_bichecked(const void* px,const void* py,Args&&... args):
tr1{px},tr2{py!=px?py:nullptr},lck{std::forward<Args>(args)...}{}
void unlock()
{
lck.unlock();
tr2.clear();
tr1.clear();
}
entry_trace tr1,tr2;
LockGuard lck;
};
#else
template<typename LockGuard>
@ -125,6 +144,18 @@ struct reentrancy_checked
LockGuard lck;
};
template<typename LockGuard>
struct reentrancy_bichecked
{
template<typename... Args>
reentrancy_bichecked(const void*,const void*,Args&&... args):
lck{std::forward<Args>(args)...}{}
void unlock(){lck.unlock();}
LockGuard lck;
};
#endif
} /* namespace foa */