mirror of
https://github.com/twisterarmy/twister-core.git
synced 2025-01-24 05:24:34 +00:00
Merge pull request #2004 from alexanderkjeldaas/simplify-cmutexlock
Simplify CMutexLock
This commit is contained in:
commit
3ed1ccb089
22
src/sync.h
22
src/sync.h
@ -37,11 +37,8 @@ class CMutexLock
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
boost::unique_lock<Mutex> lock;
|
boost::unique_lock<Mutex> lock;
|
||||||
public:
|
|
||||||
|
|
||||||
void Enter(const char* pszName, const char* pszFile, int nLine)
|
void Enter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
|
||||||
if (!lock.owns_lock())
|
|
||||||
{
|
{
|
||||||
EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()));
|
EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()));
|
||||||
#ifdef DEBUG_LOCKCONTENTION
|
#ifdef DEBUG_LOCKCONTENTION
|
||||||
@ -54,29 +51,17 @@ public:
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
void Leave()
|
|
||||||
{
|
|
||||||
if (lock.owns_lock())
|
|
||||||
{
|
|
||||||
lock.unlock();
|
|
||||||
LeaveCritical();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
|
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
|
||||||
{
|
|
||||||
if (!lock.owns_lock())
|
|
||||||
{
|
{
|
||||||
EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true);
|
EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true);
|
||||||
lock.try_lock();
|
lock.try_lock();
|
||||||
if (!lock.owns_lock())
|
if (!lock.owns_lock())
|
||||||
LeaveCritical();
|
LeaveCritical();
|
||||||
}
|
|
||||||
return lock.owns_lock();
|
return lock.owns_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
|
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
|
||||||
{
|
{
|
||||||
if (fTry)
|
if (fTry)
|
||||||
@ -95,11 +80,6 @@ public:
|
|||||||
{
|
{
|
||||||
return lock.owns_lock();
|
return lock.owns_lock();
|
||||||
}
|
}
|
||||||
|
|
||||||
boost::unique_lock<Mutex> &GetLock()
|
|
||||||
{
|
|
||||||
return lock;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef CMutexLock<CCriticalSection> CCriticalBlock;
|
typedef CMutexLock<CCriticalSection> CCriticalBlock;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user