[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [KDevPlatform] bae38ce: Use pthread directly for the foreground mutex,
From:       David Nolden <david.nolden.kde () art-master ! de>
Date:       2010-12-01 16:58:15
Message-ID: 20101201165815.BC169A60A6 () git ! kde ! org
[Download RAW message or body]

commit bae38ceb983f7c7b0b66ca475dbfa689ace8313e
branch master
Author: David Nolden <david.nolden.kde@art-master.de>
Date:   Wed Dec 1 17:53:52 2010 +0100

    Use pthread directly for the foreground mutex, potentially trying to workaround a problem \
in the QMutex implementation which leads to a rare deadlock.  BUG: 252659

diff --git a/interfaces/CMakeLists.txt b/interfaces/CMakeLists.txt
index 4fd1ec4..d832c85 100644
--- a/interfaces/CMakeLists.txt
+++ b/interfaces/CMakeLists.txt
@@ -49,7 +49,8 @@ target_link_libraries(kdevplatforminterfaces
         ${KDE4_KTEXTEDITOR_LIBS} 
         ${KDE4_THREADWEAVER_LIBRARIES} 
         ${QT_QTDESIGNER_LIBRARY} 
-        ${KDE4_KROSSCORE_LIBS})
+        ${KDE4_KROSSCORE_LIBS}
+        rt)
 target_link_libraries(kdevplatforminterfaces LINK_INTERFACE_LIBRARIES 
         ${KDE4_KPARTS_LIBS} 
         ${KDE4_KTEXTEDITOR_LIBS} 
diff --git a/interfaces/foregroundlock.cpp b/interfaces/foregroundlock.cpp
index ada7db9..4e3a73d 100644
--- a/interfaces/foregroundlock.cpp
+++ b/interfaces/foregroundlock.cpp
@@ -24,8 +24,65 @@
 
 using namespace KDevelop;
 
+#define USE_PTHREAD_MUTEX
+
+#ifdef USE_PTHREAD_MUTEX
+
+#include <pthread.h>
+#include <time.h>
+
+
+class SimplePThreadMutex {
+public:
+    SimplePThreadMutex() {
+        m_mutex = PTHREAD_MUTEX_INITIALIZER;
+        int result = pthread_mutex_init(&m_mutex, 0);
+        Q_ASSERT(result == 0);
+    }
+    ~SimplePThreadMutex() {
+        pthread_mutex_destroy(&m_mutex);
+    }
+    void lock() {
+        int result = pthread_mutex_lock(&m_mutex);
+        Q_ASSERT(result == 0);
+    }
+    void unlock() {
+        int result = pthread_mutex_unlock(&m_mutex);
+        Q_ASSERT(result == 0);
+    }
+    bool tryLock(int interval) {
+        if(interval == 0)
+        {
+            int result = pthread_mutex_trylock(&m_mutex);
+            return result == 0;
+        }else{
+            timespec abs_time;
+            clock_gettime(CLOCK_REALTIME, &abs_time);
+            abs_time.tv_nsec += interval * 1000000;
+            if(abs_time.tv_nsec >= 1000000000)
+            {
+                abs_time.tv_nsec -= 1000000000;
+                abs_time.tv_sec += 1;
+            }
+            
+            int result = pthread_mutex_timedlock(&m_mutex, &abs_time);
+            return result == 0;
+        }
+    }
+    
+private:
+    pthread_mutex_t m_mutex;
+};
+
 namespace {
+
+SimplePThreadMutex internalMutex;
+#else
+
+namespace {
+
 QMutex internalMutex;
+#endif
 QMutex tryLockMutex;
 QMutex waitMutex;
 QMutex finishMutex;


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic