[Kst] extragear/graphics/kst

George Staikos staikos at kde.org
Fri Aug 11 04:20:50 CEST 2006


SVN commit 571895 by staikos:

Add a new configure option to make Kst use a single global lock.  Use this
option if you experience deadlocks as a temporary workaround.  Remember to
rebuild all plugins when you change this setting


 M  +6 -1      configure.in.in  
 M  +1 -1      src/libkst/kstdatasource.h  
 M  +32 -17    src/libkst/rwlock.cpp  
 M  +7 -1      src/libkst/rwlock.h  


--- trunk/extragear/graphics/kst/configure.in.in #571894:571895
@@ -320,6 +320,11 @@
     [
         AC_DEFINE(HAVE_KST_USE_TIMERS, 1, [Define if we should compile in timers])
     ])
-
 AM_CONFIG_HEADER([kst/src/libkst/ksttimers.h])
 
+AC_ARG_WITH(one-lock,
+    AC_HELP_STRING([--with-one-lock],[build an effectively single-threaded Kst]),
+    [
+        AC_DEFINE(ONE_LOCK_TO_RULE_THEM_ALL, 1, [Define if we should build with only one mutex])
+    ])
+
--- trunk/extragear/graphics/kst/src/libkst/kstdatasource.h #571894:571895
@@ -30,7 +30,7 @@
 #include "kstobject.h"
 #include "kst_export.h"
 
-#define KST_CURRENT_DATASOURCE_KEY 0x00000005
+#define KST_CURRENT_DATASOURCE_KEY 0x00000006
 
 #define KST_KEY_DATASOURCE_PLUGIN(x) extern "C" Q_UINT32 key_##x() { return KST_CURRENT_DATASOURCE_KEY; }
 
--- trunk/extragear/graphics/kst/src/libkst/rwlock.cpp #571894:571895
@@ -21,6 +21,9 @@
 
 //#define LOCKTRACE
 
+#ifdef ONE_LOCK_TO_RULE_THEM_ALL
+QMutex KstRWLock::_mutex(true);
+#endif
 
 KstRWLock::KstRWLock()
 : _readCount(0), _writeCount(0), _waitingReaders(0), _waitingWriters(0) {
@@ -32,19 +35,20 @@
 
 
 void KstRWLock::readLock() const {
+#ifndef ONE_LOCK_TO_RULE_THEM_ALL
   QMutexLocker lock(&_mutex);
   
-  #ifdef LOCKTRACE
+#ifdef LOCKTRACE
   kstdDebug() << (void*)this << " KstRWLock::readLock() by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#endif
 
   Qt::HANDLE me = QThread::currentThread();
 
   if (_writeCount > 0 && _writeLocker == me) {
     // thread already has a write lock
-    #ifdef LOCKTRACE
+#ifdef LOCKTRACE
     kstdDebug() << "Thread " << (int)QThread::currentThread() << " has a write lock on KstRWLock " << (void*)this << ", getting a read lock" << endl;
-    #endif
+#endif
   } else {
     while (_writeCount > 0 || _waitingWriters) {
       ++_waitingReaders;
@@ -56,18 +60,22 @@
   _readLockers[me] = _readLockers[me] + 1;
   ++_readCount;
 
-  #ifdef LOCKTRACE
-  //kstdDebug() << (void*)this << " KstRWLock::readLock() done by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#ifdef LOCKTRACE
+  kstdDebug() << (void*)this << " KstRWLock::readLock() done by tid=" << (int)QThread::currentThread() << endl;
+#endif
+#else
+  _mutex.lock();
+#endif
 }
 
 
 void KstRWLock::writeLock() const {
+#ifndef ONE_LOCK_TO_RULE_THEM_ALL
   QMutexLocker lock(&_mutex);
 
-  #ifdef LOCKTRACE
+#ifdef LOCKTRACE
   kstdDebug() << (void*)this << " KstRWLock::writeLock() by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#endif
 
   Qt::HANDLE me = QThread::currentThread();
 
@@ -88,18 +96,22 @@
   _writeLocker = me;
   ++_writeCount;
 
-  #ifdef LOCKTRACE
-  //kstdDebug() << (void*)this << " KstRWLock::writeLock() done by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#ifdef LOCKTRACE
+  kstdDebug() << (void*)this << " KstRWLock::writeLock() done by tid=" << (int)QThread::currentThread() << endl;
+#endif
+#else
+  _mutex.lock();
+#endif
 }
 
 
 void KstRWLock::unlock() const {
+#ifndef ONE_LOCK_TO_RULE_THEM_ALL
   QMutexLocker lock(&_mutex);
 
-  #ifdef LOCKTRACE
+#ifdef LOCKTRACE
   kstdDebug() << (void*)this << " KstRWLock::unlock() by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#endif
 
   Qt::HANDLE me = QThread::currentThread();
 
@@ -140,9 +152,12 @@
     }
   }
 
-  #ifdef LOCKTRACE
-  //kstdDebug() << (void*)this << " KstRWLock::unlock() done by tid=" << (int)QThread::currentThread() << endl;
-  #endif
+#ifdef LOCKTRACE
+  kstdDebug() << (void*)this << " KstRWLock::unlock() done by tid=" << (int)QThread::currentThread() << endl;
+#endif
+#else
+  _mutex.unlock();
+#endif
 }
 
 
--- trunk/extragear/graphics/kst/src/libkst/rwlock.h #571894:571895
@@ -24,6 +24,7 @@
 
 #include "kstwaitcondition.h"
 
+#include "config.h"
 #include "kst_export.h"
 
 class KST_EXPORT KstRWLock {
@@ -37,7 +38,12 @@
     virtual void unlock() const;
 
   protected:
-    mutable QMutex _mutex;
+#ifdef ONE_LOCK_TO_RULE_THEM_ALL
+    static
+#else
+    mutable
+#endif
+    QMutex _mutex;
     mutable KstWaitCondition _readerWait, _writerWait;
 
     mutable int _readCount, _writeCount;


More information about the Kst mailing list