[Kst] kst_concurrent_branch: kdeextragear-2/kst/kst

George Staikos staikos at kde.org
Fri Feb 27 00:51:10 CET 2004


CVS commit by staikos: 

fix a locking bug, and make write locking recursion safe.  This does not apply
for mixing read and write locking recursively [yet]


  M +5 -2      kstpsddialog_i.cpp   1.28.2.2
  M +11 -3     rwlock.cpp   1.1.4.2
  M +3 -0      rwlock.h   1.1.4.2


--- kdeextragear-2/kst/kst/kstpsddialog_i.cpp  #1.28.2.1:1.28.2.2
@@ -223,5 +223,5 @@ void KstPsdDialogI::new_I() {
 
   {
-    KstReadLocker ml(&KST::vectorList.lock());
+    KST::vectorList.lock().readLock();
     KstVectorList::Iterator i = KST::vectorList.findTag(_vector->selectedVector());
     if (i == KST::vectorList.end()) {
@@ -230,6 +230,9 @@ void KstPsdDialogI::new_I() {
     }
 
+    KstVectorPtr p = *i;
+    KST::vectorList.lock().readUnlock();
+
     /* create the psd curve */
-    curve = new KstPSDCurve(tag_name, *i, new_freq, new_len,
+    curve = new KstPSDCurve(tag_name, p, new_freq, new_len,
                             VectorUnits->text(), RateUnits->text(),
                             _curveAppearance->color());

--- kdeextragear-2/kst/kst/rwlock.cpp  #1.1.4.1:1.1.4.2
@@ -23,5 +23,5 @@
 
 KstRWLock::KstRWLock()
-: _sem(MAXREADERS) {
+: _sem(MAXREADERS), _writeLock(true), _writeRecursion(0) {
 }
 
@@ -46,6 +46,10 @@ void KstRWLock::readUnlock() const {
 
 void KstRWLock::writeLock() const {
+  _writeLock.lock();
   //printf("%p Write lock %d/%d\n", (void*)this, _sem.available(), _sem.total());
+  if (_writeRecursion == 0) {
   _sem += MAXREADERS;
+  }
+  _writeRecursion++;
   //printf("%p Write locked %d/%d\n", (void*)this, _sem.available(), _sem.total());
 }
@@ -54,6 +58,10 @@ void KstRWLock::writeLock() const {
 void KstRWLock::writeUnlock() const {
   //printf("%p Write unlock %d/%d\n", (void*)this, _sem.available(), _sem.total());
+  _writeRecursion--;
+  if (_writeRecursion == 0) {
   _sem -= MAXREADERS;
+  }
   //printf("%p Write unlocked %d/%d\n", (void*)this, _sem.available(), _sem.total());
+  _writeLock.unlock();
 }
 

--- kdeextragear-2/kst/kst/rwlock.h  #1.1.4.1:1.1.4.2
@@ -19,4 +19,5 @@
 #define RWLOCK_H
 
+#include <qmutex.h>
 #include <qsemaphore.h>
 
@@ -34,4 +35,6 @@ class KstRWLock {
   protected:
     mutable QSemaphore _sem;
+    mutable QMutex _writeLock;
+    mutable int _writeRecursion;
 };
 





More information about the Kst mailing list