diff options
| author | Greg Clayton <gclayton@apple.com> | 2010-09-03 19:15:43 +0000 |
|---|---|---|
| committer | Greg Clayton <gclayton@apple.com> | 2010-09-03 19:15:43 +0000 |
| commit | 54512bd6c9bed0a7ed0e0d6d957442dd4c40fee3 (patch) | |
| tree | 5a5ee6430cc39884bd172eb652b6b9f961fe834c /lldb/source/Host/posix/Mutex.cpp | |
| parent | 78395e4b8a5cd56fef0df65811826e51e8ab104f (diff) | |
| download | bcm5719-llvm-54512bd6c9bed0a7ed0e0d6d957442dd4c40fee3.tar.gz bcm5719-llvm-54512bd6c9bed0a7ed0e0d6d957442dd4c40fee3.zip | |
Fixed a case where we might be able to acquire a mutex with a try lock and
not release it by making sure a mutex locker object is appropriately used.
llvm-svn: 112996
Diffstat (limited to 'lldb/source/Host/posix/Mutex.cpp')
| -rw-r--r-- | lldb/source/Host/posix/Mutex.cpp | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lldb/source/Host/posix/Mutex.cpp b/lldb/source/Host/posix/Mutex.cpp index 3f1c8306699..e038102e98c 100644 --- a/lldb/source/Host/posix/Mutex.cpp +++ b/lldb/source/Host/posix/Mutex.cpp @@ -78,8 +78,7 @@ Mutex::Locker::Locker (pthread_mutex_t *mutex_ptr) : //---------------------------------------------------------------------- Mutex::Locker::~Locker () { - if (m_mutex_ptr) - Mutex::Unlock (m_mutex_ptr); + Reset(); } //---------------------------------------------------------------------- @@ -89,6 +88,10 @@ Mutex::Locker::~Locker () void Mutex::Locker::Reset (pthread_mutex_t *mutex_ptr) { + // We already have this mutex locked or both are NULL... + if (m_mutex_ptr == mutex_ptr) + return; + if (m_mutex_ptr) Mutex::Unlock (m_mutex_ptr); @@ -100,9 +103,12 @@ Mutex::Locker::Reset (pthread_mutex_t *mutex_ptr) bool Mutex::Locker::TryLock (pthread_mutex_t *mutex_ptr) { - if (m_mutex_ptr) - Mutex::Unlock (m_mutex_ptr); - m_mutex_ptr = NULL; + // We already have this mutex locked! + if (m_mutex_ptr == mutex_ptr) + return true; + + Reset (); + if (mutex_ptr) { if (Mutex::TryLock (mutex_ptr) == 0) |

