diff options
Diffstat (limited to 'src/ccapi/common/win/OldCC/autolock.hxx')
-rw-r--r-- | src/ccapi/common/win/OldCC/autolock.hxx | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/ccapi/common/win/OldCC/autolock.hxx b/src/ccapi/common/win/OldCC/autolock.hxx index bbd773488c..45b881e221 100644 --- a/src/ccapi/common/win/OldCC/autolock.hxx +++ b/src/ccapi/common/win/OldCC/autolock.hxx @@ -35,10 +35,8 @@ public: ~CcOsLock() {DeleteCriticalSection(&cs); valid = false;} void lock() {if (valid) EnterCriticalSection(&cs);} void unlock() {if (valid) LeaveCriticalSection(&cs);} -#if 0 bool trylock() {return valid ? (TryEnterCriticalSection(&cs) ? true : false) : false; } -#endif }; class CcAutoLock { @@ -50,4 +48,13 @@ public: ~CcAutoLock() { m_lock.unlock(); } }; +class CcAutoTryLock { + CcOsLock& m_lock; + bool m_locked; +public: + CcAutoTryLock(CcOsLock& lock):m_lock(lock) { m_locked = m_lock.trylock(); } + ~CcAutoTryLock() { if (m_locked) m_lock.unlock(); m_locked = false; } + bool IsLocked() const { return m_locked; } +}; + #endif /* __AUTOLOCK_HXX */ |