From 8afe162910d08a29712582f2b4f13a051a4d8599 Mon Sep 17 00:00:00 2001 From: Peter Dimov Date: Sun, 7 Jun 2020 21:07:35 +0300 Subject: [PATCH] Use a relaxed load before XCHG to not lock cache line on contention (AMD spinlock recommendation per ) --- include/boost/smart_ptr/detail/spinlock_w32.hpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/boost/smart_ptr/detail/spinlock_w32.hpp b/include/boost/smart_ptr/detail/spinlock_w32.hpp index 39092ce..ddaf4ff 100644 --- a/include/boost/smart_ptr/detail/spinlock_w32.hpp +++ b/include/boost/smart_ptr/detail/spinlock_w32.hpp @@ -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