From 39d0adc13b5c82193199c2f0c5445aa3feaa60eb Mon Sep 17 00:00:00 2001 From: Egor Yusov Date: Mon, 27 Aug 2018 22:55:19 -0700 Subject: Updated LockHelper to spin few times before yielding thread --- Common/interface/LockHelper.h | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'Common/interface') diff --git a/Common/interface/LockHelper.h b/Common/interface/LockHelper.h index 0605bfb5..8d30089d 100644 --- a/Common/interface/LockHelper.h +++ b/Common/interface/LockHelper.h @@ -96,11 +96,19 @@ public: return false; } + static constexpr const int SpinCountToYield = 256; + static void UnsafeLock(LockFlag &LockFlag) { + int SpinCount = 0; while( !UnsafeTryLock( LockFlag ) ) { - YieldThread(); + ++SpinCount; + if(SpinCount == SpinCountToYield) + { + SpinCount = 0; + YieldThread(); + } } } @@ -108,9 +116,15 @@ public: { VERIFY( m_pLockFlag == NULL, "Object already locked" ); // Wait for the flag to become unlocked and lock it + int SpinCount = 0; while( !TryLock( LockFlag ) ) { - YieldThread(); + ++SpinCount; + if(SpinCount == SpinCountToYield) + { + SpinCount = 0; + YieldThread(); + } } } -- cgit v1.2.3