Use a relaxed load before XCHG to not lock cache line on contention (AMD spinlock recommendation per <https://probablydance.com/2019/12/30/measuring-mutexes-spinlocks-and-how-bad-the-linux-scheduler-really-is/>)

This commit is contained in:
Peter Dimov
2020-06-07 21:07:35 +03:00
parent 5d31c1c443
commit 8afe162910

View File

@ -66,6 +66,11 @@ public:
bool try_lock()
{
if( *const_cast< long const volatile* >( &v_ ) != 0 )
{
return false;
}
long r = BOOST_SP_INTERLOCKED_EXCHANGE( &v_, 1 );
BOOST_COMPILER_FENCE