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.
git-svn-id: https://llvm.org/svn/llvm-project/llvdb/trunk@112996 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/source/Host/posix/Mutex.cpp b/source/Host/posix/Mutex.cpp
index 3f1c830..e038102 100644
--- a/source/Host/posix/Mutex.cpp
+++ b/source/Host/posix/Mutex.cpp
@@ -78,8 +78,7 @@
//----------------------------------------------------------------------
Mutex::Locker::~Locker ()
{
- if (m_mutex_ptr)
- Mutex::Unlock (m_mutex_ptr);
+ Reset();
}
//----------------------------------------------------------------------
@@ -89,6 +88,10 @@
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 @@
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)