diff options
author | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-06 04:11:14 -0700 |
---|---|---|
committer | Pieter Wuille <pieter.wuille@gmail.com> | 2012-04-06 04:11:14 -0700 |
commit | 9362da78b0d8f0dd7bbad259adcb3e4d0cf58e56 (patch) | |
tree | 9abfb65cfff9b76217e72e55608baa357274f1f1 /src/util.cpp | |
parent | 9682087b65b820f24579871946731445302a1a5a (diff) | |
parent | 092631f0ba0030dec1ccfa66e206fb2a6c9bf73b (diff) |
Merge pull request #1033 from sipa/wait
Condition variables instead of polling
Diffstat (limited to 'src/util.cpp')
-rw-r--r-- | src/util.cpp | 56 |
1 files changed, 4 insertions, 52 deletions
diff --git a/src/util.cpp b/src/util.cpp index 5c47551526..d55e7ae10e 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -1183,62 +1183,14 @@ static void pop_lock() dd_mutex.unlock(); } -void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine) +void EnterCritical(const char* pszName, const char* pszFile, int nLine, void* cs) { - push_lock(this, CLockLocation(pszName, pszFile, nLine)); -#ifdef DEBUG_LOCKCONTENTION - bool result = mutex.try_lock(); - if (!result) - { - printf("LOCKCONTENTION: %s\n", pszName); - printf("Locker: %s:%d\n", pszFile, nLine); - mutex.lock(); - printf("Locked\n"); - } -#else - mutex.lock(); -#endif -} -void CCriticalSection::Leave() -{ - mutex.unlock(); - pop_lock(); -} -bool CCriticalSection::TryEnter(const char* pszName, const char* pszFile, int nLine) -{ - push_lock(this, CLockLocation(pszName, pszFile, nLine)); - bool result = mutex.try_lock(); - if (!result) pop_lock(); - return result; + push_lock(cs, CLockLocation(pszName, pszFile, nLine)); } -#else - -void CCriticalSection::Enter(const char* pszName, const char* pszFile, int nLine) +void LeaveCritical() { -#ifdef DEBUG_LOCKCONTENTION - bool result = mutex.try_lock(); - if (!result) - { - printf("LOCKCONTENTION: %s\n", pszName); - printf("Locker: %s:%d\n", pszFile, nLine); - mutex.lock(); - } -#else - mutex.lock(); -#endif -} - -void CCriticalSection::Leave() -{ - mutex.unlock(); -} - -bool CCriticalSection::TryEnter(const char*, const char*, int) -{ - bool result = mutex.try_lock(); - return result; + pop_lock(); } #endif /* DEBUG_LOCKORDER */ - |