[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-11-19 14:54:33
Message-ID: 20101119145433.C555AAC8A5 () svn ! kde ! org
[Download RAW message or body]

SVN commit 1198748 by trueg:

Properly cancel the count runnable like we do with the search runnable.

 M  +29 -0     countqueryrunnable.cpp  
 M  +7 -0      countqueryrunnable.h  
 M  +8 -2      folder.cpp  
 M  +2 -0      folder.h  
 M  +1 -2      searchrunnable.h  


--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/countqueryrunnable.cpp \
#1198747:1198748 @@ -31,7 +31,10 @@
 
 #include <KDebug>
 
+#include <QtCore/QMutexLocker>
+#include <QtCore/QTime>
 
+
 Nepomuk::Query::CountQueryRunnable::CountQueryRunnable( Folder* folder )
     : QRunnable(),
       m_folder( folder )
@@ -45,16 +48,42 @@
 }
 
 
+void Nepomuk::Query::CountQueryRunnable::cancel()
+{
+    // "detach" us from the folder which will most likely be deleted now
+    QMutexLocker lock( &m_folderMutex );
+    m_folder = 0;
+}
+
+
 void Nepomuk::Query::CountQueryRunnable::run()
 {
+    QMutexLocker lock( &m_folderMutex );
+    if( !m_folder )
+        return;
+
     int count = -1;
     Query query = m_folder->query();
+    lock.unlock();
+
+#ifndef NDEBUG
+    QTime time;
+    time.start();
+#endif
+
     QString sparql = query.toSparqlQuery( Query::CreateCountQuery );
     Soprano::QueryResultIterator it = \
ResourceManager::instance()->mainModel()->executeQuery( sparql, \
Soprano::Query::QueryLanguageSparql );  if( it.next() ) {
         count = it.binding( 0 ).literal().toInt();
     }
     kDebug() << "Count:" << count;
+
+#ifndef NDEBUG
+    kDebug() << time.elapsed();
+#endif
+
+    lock.relock();
+
     if( m_folder )
         m_folder->countQueryFinished( count );
 }
--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/countqueryrunnable.h \
#1198747:1198748 @@ -23,6 +23,7 @@
 
 #include <QtCore/QRunnable>
 #include <QtCore/QPointer>
+#include <QtCore/QMutex>
 
 #include "folder.h"
 
@@ -36,10 +37,16 @@
             CountQueryRunnable( Folder* folder );
             ~CountQueryRunnable();
 
+            /**
+             * Cancel the search and detach it from the folder.
+             */
+            void cancel();
+
             void run();
 
         private:
             QPointer<Folder> m_folder;
+            QMutex m_folderMutex;
         };
     }
 }
--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/folder.cpp \
#1198747:1198748 @@ -47,7 +47,8 @@
       m_isSparqlQueryFolder( true ),
       m_sparqlQuery( query ),
       m_requestProperties( requestProps ),
-      m_currentSearchRunnable( 0 )
+      m_currentSearchRunnable( 0 ),
+      m_currentCountQueryRunnable( 0 )
 {
     init();
 }
@@ -75,6 +76,8 @@
 {
     if( m_currentSearchRunnable )
         m_currentSearchRunnable->cancel();
+    if( m_currentCountQueryRunnable )
+        m_currentCountQueryRunnable->cancel();
 
     // cannot use qDeleteAll since deleting a connection changes m_connections
     while ( !m_connections.isEmpty() )
@@ -91,7 +94,8 @@
         // we only need the count for initialListingDone
         if ( !m_initialListingDone &&
              !m_isSparqlQueryFolder ) {
-            QueryService::searchThreadPool()->start( new CountQueryRunnable( this ), \
0 ); +            m_currentCountQueryRunnable = new CountQueryRunnable( this );
+            QueryService::searchThreadPool()->start( m_currentCountQueryRunnable, 0 \
);  }
     }
 }
@@ -205,6 +209,8 @@
 // called from CountQueryRunnable in the search thread
 void Nepomuk::Query::Folder::countQueryFinished( int count )
 {
+    m_currentCountQueryRunnable = 0;
+
     m_resultCount = count;
     kDebug() << m_resultCount;
     if( count >= 0 )
--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/folder.h #1198747:1198748
@@ -40,6 +40,7 @@
     namespace Query {
 
         class SearchRunnable;
+        class CountQueryRunnable;
         class FolderConnection;
 
         /**
@@ -162,6 +163,7 @@
 
             /// the runnable doing work at the moment or 0 if idle
             SearchRunnable* m_currentSearchRunnable;
+            CountQueryRunnable* m_currentCountQueryRunnable;
 
             /// did the nepomuk store change after the last update - used for \
caching of update signals via m_updateTimer  bool m_storageChanged;
--- trunk/KDE/kdebase/runtime/nepomuk/services/queryservice/searchrunnable.h \
#1198747:1198748 @@ -44,8 +44,7 @@
             ~SearchRunnable();
 
             /**
-             * Cancel the search. When this method returns
-             * the runnable is not running.
+             * Cancel the search and detach it from the folder.
              */
             void cancel();
 


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

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