aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2012-11-24 13:55:00 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2012-11-24 13:55:00 -0800
commit3ed1ccb0898b22353e9fcc942b43df98c9a3bf4c (patch)
tree65ce94156217689b16702f7526d8f5326f6e7418 /src
parent7818d230a20c320473a9bfa5ebddc861724b917e (diff)
parentbfc96207998c284e2cb6eb99c99b755a161e723d (diff)
Merge pull request #2004 from alexanderkjeldaas/simplify-cmutexlock
Simplify CMutexLock
Diffstat (limited to 'src')
-rw-r--r--src/sync.h40
1 files changed, 10 insertions, 30 deletions
diff --git a/src/sync.h b/src/sync.h
index e80efbe001..9dfc6697c6 100644
--- a/src/sync.h
+++ b/src/sync.h
@@ -37,46 +37,31 @@ class CMutexLock
{
private:
boost::unique_lock<Mutex> lock;
-public:
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
- if (!lock.try_lock())
- {
- PrintLockContention(pszName, pszFile, nLine);
+ if (!lock.try_lock())
+ {
+ PrintLockContention(pszName, pszFile, nLine);
#endif
- lock.lock();
+ lock.lock();
#ifdef DEBUG_LOCKCONTENTION
- }
-#endif
- }
- }
-
- void Leave()
- {
- if (lock.owns_lock())
- {
- lock.unlock();
- LeaveCritical();
}
+#endif
}
bool TryEnter(const char* pszName, const char* pszFile, int nLine)
{
+ EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true);
+ lock.try_lock();
if (!lock.owns_lock())
- {
- EnterCritical(pszName, pszFile, nLine, (void*)(lock.mutex()), true);
- lock.try_lock();
- if (!lock.owns_lock())
- LeaveCritical();
- }
+ LeaveCritical();
return lock.owns_lock();
}
+public:
CMutexLock(Mutex& mutexIn, const char* pszName, const char* pszFile, int nLine, bool fTry = false) : lock(mutexIn, boost::defer_lock)
{
if (fTry)
@@ -95,11 +80,6 @@ public:
{
return lock.owns_lock();
}
-
- boost::unique_lock<Mutex> &GetLock()
- {
- return lock;
- }
};
typedef CMutexLock<CCriticalSection> CCriticalBlock;