mirror of
https://github.com/boostorg/smart_ptr.git
synced 2025-07-31 13:17:23 +02:00
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:
@ -66,6 +66,11 @@ public:
|
|||||||
|
|
||||||
bool try_lock()
|
bool try_lock()
|
||||||
{
|
{
|
||||||
|
if( *const_cast< long const volatile* >( &v_ ) != 0 )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
long r = BOOST_SP_INTERLOCKED_EXCHANGE( &v_, 1 );
|
long r = BOOST_SP_INTERLOCKED_EXCHANGE( &v_, 1 );
|
||||||
|
|
||||||
BOOST_COMPILER_FENCE
|
BOOST_COMPILER_FENCE
|
||||||
|
Reference in New Issue
Block a user