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

List:       kde-commits
Subject:    KDE/kdebase/runtime/nepomuk/services/queryservice
From:       Sebastian Trueg <sebastian () trueg ! de>
Date:       2010-10-22 14:28:08
Message-ID: 20101022142808.21407AC897 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1188518 by trueg:

A funny way to make sure the runnable will never call a method on a deleted Folder:
in the cancel() method we try to lock a mutex that the runnable locks in its run() \
method. Thus, once the cancel() method returns we can be sure that the last call to a \
Folder method has been done.


 M  +10 -0     searchrunnable.cpp  
 M  +8 -0      searchrunnable.h  


--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/searchrunnable.cpp \
#1188517:1188518 @@ -69,14 +69,22 @@
 void Nepomuk::Query::SearchRunnable::cancel()
 {
     m_canceled = true;
+    // we wait for the runnable to finish by locking the mutex the run() method \
locks, too +    QMutexLocker lock( &m_cancelMutex );
 }
 
 
 void Nepomuk::Query::SearchRunnable::run()
 {
+    if( m_canceled )
+        return;
+
     QTime time;
     time.start();
 
+    // lock the cancel mutex to make the cancel() method block until we are actually \
done +    m_cancelMutex.lock();
+
     m_resultCnt = 0;
 
     Soprano::QueryResultIterator hits = \
ResourceManager::instance()->mainModel()->executeQuery( m_folder->sparqlQuery(), \
Soprano::Query::QueryLanguageSparql ); @@ -95,6 +103,8 @@
             break;
     }
 
+    m_cancelMutex.unlock();
+
     kDebug() << time.elapsed();
 
     if( m_folder && !m_canceled )
--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/searchrunnable.h \
#1188517:1188518 @@ -22,6 +22,7 @@
 
 #include <QtCore/QRunnable>
 #include <QtCore/QPointer>
+#include <QtCore/QMutex>
 
 #include <Nepomuk/Query/Result>
 
@@ -42,6 +43,10 @@
             SearchRunnable( Folder* folder );
             ~SearchRunnable();
 
+            /**
+             * Cancel the search. When this method returns
+             * the runnable is not running.
+             */
             void cancel();
 
         Q_SIGNALS:
@@ -58,6 +63,9 @@
             // status
             bool m_canceled;
             int m_resultCnt;
+
+            // used only for ensuring that the runnable is actually done after a \
call to cancel() +            QMutex m_cancelMutex;
         };
     }
 }


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

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