[Lldb-commits] [lldb] r163975 - in /lldb/branches/windows: include/lldb/Host/Mutex.h source/Host/common/Condition.cpp source/Host/common/Mutex.cpp

Carlo Kok ck at remobjects.com
Sat Sep 15 11:17:02 PDT 2012


Author: carlokok
Date: Sat Sep 15 13:17:01 2012
New Revision: 163975

URL: http://llvm.org/viewvc/llvm-project?rev=163975&view=rev
Log:
Mutex & Condition now work together and allow conditions to wait while unlocking a mutex (before it got stuck)

Modified:
    lldb/branches/windows/include/lldb/Host/Mutex.h
    lldb/branches/windows/source/Host/common/Condition.cpp
    lldb/branches/windows/source/Host/common/Mutex.cpp

Modified: lldb/branches/windows/include/lldb/Host/Mutex.h
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/windows/include/lldb/Host/Mutex.h?rev=163975&r1=163974&r2=163975&view=diff
==============================================================================
--- lldb/branches/windows/include/lldb/Host/Mutex.h (original)
+++ lldb/branches/windows/include/lldb/Host/Mutex.h Sat Sep 15 13:17:01 2012
@@ -16,6 +16,11 @@
 #ifdef _POSIX_SOURCE
 #include <pthread.h>
 #endif
+#ifdef _WIN32
+#define WIN32_LEAN_AND_MEAN
+#define NOMINMAX
+#include <Windows.h>
+#endif
 
 #include <assert.h>
 
@@ -257,8 +262,12 @@
 #endif
 
 #ifndef _POSIX_SOURCE
+#ifdef _WIN32
+    CRITICAL_SECTION* m_mutex;
+#else
     llvm::sys::MutexImpl m_mutex;
 #endif
+#endif
 
     Mutex(const Mutex&);
     const Mutex& operator=(const Mutex&);

Modified: lldb/branches/windows/source/Host/common/Condition.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/windows/source/Host/common/Condition.cpp?rev=163975&r1=163974&r2=163975&view=diff
==============================================================================
--- lldb/branches/windows/source/Host/common/Condition.cpp (original)
+++ lldb/branches/windows/source/Host/common/Condition.cpp Sat Sep 15 13:17:01 2012
@@ -104,11 +104,15 @@
 {
 #ifdef _WIN32
     DWORD wait = INFINITE;
-    if (abstime != NULL)
-        wait = tv2ms(abstime->GetAsTimeVal());
+    if (abstime != NULL) {
+        int wval = (*abstime - TimeValue::Now()) / 1000000;
+        if (wval < 0) wval = 0;
 
-    int err = SleepConditionVariableCS(&m_condition, (PCRITICAL_SECTION)&mutex,
-        wait);
+        wait = wval;
+    }
+    
+    
+    int err = SleepConditionVariableCS(&m_condition, mutex.m_mutex, wait);
 
     if (timed_out != NULL)
     {

Modified: lldb/branches/windows/source/Host/common/Mutex.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/branches/windows/source/Host/common/Mutex.cpp?rev=163975&r1=163974&r2=163975&view=diff
==============================================================================
--- lldb/branches/windows/source/Host/common/Mutex.cpp (original)
+++ lldb/branches/windows/source/Host/common/Mutex.cpp Sat Sep 15 13:17:01 2012
@@ -183,7 +183,10 @@
 Mutex::Mutex () :
     m_mutex()
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    m_mutex = new CRITICAL_SECTION();
+    InitializeCriticalSection(m_mutex);
+#else
     int err;
     err = ::pthread_mutex_init (&m_mutex, NULL);
 #if ENABLE_MUTEX_ERROR_CHECKING
@@ -202,7 +205,10 @@
 Mutex::Mutex (Mutex::Type type) :
     m_mutex()
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    m_mutex = new CRITICAL_SECTION();
+    InitializeCriticalSection(m_mutex);
+#else
     int err;
     ::pthread_mutexattr_t attr;
     err = ::pthread_mutexattr_init (&attr);
@@ -244,7 +250,10 @@
 //----------------------------------------------------------------------
 Mutex::~Mutex()
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    DeleteCriticalSection(m_mutex);
+    delete m_mutex;
+#else
     int err;
     err = ::pthread_mutex_destroy (&m_mutex);
 #if ENABLE_MUTEX_ERROR_CHECKING
@@ -281,7 +290,10 @@
 int
 Mutex::Lock()
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    EnterCriticalSection(m_mutex);
+    return 0;
+#else
     DEBUG_LOG ("[%4.4llx/%4.4llx] pthread_mutex_lock (%p)...\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex);
 
 #if ENABLE_MUTEX_ERROR_CHECKING
@@ -301,7 +313,6 @@
     DEBUG_LOG ("[%4.4llx/%4.4llx] pthread_mutex_lock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
     return err;
 #endif
-    return m_mutex.acquire();
 }
 
 //----------------------------------------------------------------------
@@ -315,7 +326,9 @@
 int
 Mutex::TryLock(const char *failure_message)
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    return 0 == TryEnterCriticalSection(m_mutex);
+#else
 #if ENABLE_MUTEX_ERROR_CHECKING
     error_check_mutex (&m_mutex, eMutexActionAssertInitialized);
 #endif
@@ -324,7 +337,6 @@
     DEBUG_LOG ("[%4.4llx/%4.4llx] pthread_mutex_trylock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
     return err;
 #endif
-    return 0 == m_mutex.tryacquire(); // try acquire returns <> 0 for success
 }
 
 //----------------------------------------------------------------------
@@ -339,7 +351,10 @@
 int
 Mutex::Unlock()
 {
-#ifdef _POSIX_SOURCE
+#ifdef _WIN32
+    LeaveCriticalSection(m_mutex);
+   return 0;
+#else
 #if ENABLE_MUTEX_ERROR_CHECKING
     error_check_mutex (&m_mutex, eMutexActionAssertInitialized);
 #endif
@@ -356,7 +371,6 @@
     DEBUG_LOG ("[%4.4llx/%4.4llx] pthread_mutex_unlock (%p) => %i\n", Host::GetCurrentProcessID(), Host::GetCurrentThreadID(), &m_mutex, err);
     return err;
 #endif
-    return m_mutex.release();
 }
 
 #ifdef LLDB_CONFIGURATION_DEBUG





More information about the lldb-commits mailing list