diff options
| author | Egor Yusov <egor.yusov@gmail.com> | 2018-08-28 05:55:19 +0000 |
|---|---|---|
| committer | Egor Yusov <egor.yusov@gmail.com> | 2018-08-28 05:55:19 +0000 |
| commit | 39d0adc13b5c82193199c2f0c5445aa3feaa60eb (patch) | |
| tree | ad5dee34c2d321ff87ee1662d02ebb3e30efb4f9 /Common/interface | |
| parent | Removed <thread> from LockHelper.h (fixed https://github.com/DiligentGraphics... (diff) | |
| download | DiligentCore-39d0adc13b5c82193199c2f0c5445aa3feaa60eb.tar.gz DiligentCore-39d0adc13b5c82193199c2f0c5445aa3feaa60eb.zip | |
Updated LockHelper to spin few times before yielding thread
Diffstat (limited to 'Common/interface')
| -rw-r--r-- | Common/interface/LockHelper.h | 18 |
1 files changed, 16 insertions, 2 deletions
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(); + } } } |
