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

List:       kde-commits
Subject:    kdesupport/akonadi/server/src
From:       Volker Krause <vkrause () kde ! org>
Date:       2009-03-01 12:23:40
Message-ID: 1235910220.699885.22916.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 933592 by vkrause:

Rework thread termination/deletion code. We now have no more open
database connection when shutting down the db server, which contrary to
my hopes has apparently no impact on shutdown speed.


 M  +21 -26    akonadi.cpp  
 M  +0 -1      storage/itemretrievalthread.cpp  


--- trunk/kdesupport/akonadi/server/src/akonadi.cpp #933591:933592
@@ -117,7 +117,7 @@
 
     mItemRetrievalThread = new ItemRetrievalThread( this );
     mItemRetrievalThread->start( QThread::HighPriority );
-
+ 
     mSearchManager = new DummySearchManager;
 
     new ServerAdaptor( this );
@@ -136,44 +136,39 @@
 {
 }
 
+template <typename T> static void quitThread( T & thread )
+{
+  if ( !thread )
+    return;
+  thread->quit();
+  thread->wait();
+  delete thread;
+  thread = 0;
+}
+
 void AkonadiServer::quit()
 {
     if ( mAlreadyShutdown )
       return;
-
     mAlreadyShutdown = true;
 
-    if ( mItemRetrievalThread )
-      QMetaObject::invokeMethod( mItemRetrievalThread, "quit", Qt::QueuedConnection );
-    if ( mCacheCleaner )
-      QMetaObject::invokeMethod( mCacheCleaner, "quit", Qt::QueuedConnection );
-    if ( mIntervalChecker )
-      QMetaObject::invokeMethod( mIntervalChecker, "quit", Qt::QueuedConnection );
-    QCoreApplication::instance()->processEvents();
+    qDebug() << "terminating service threads";
+    quitThread( mCacheCleaner );
+    quitThread( mIntervalChecker );
+    quitThread( mItemRetrievalThread );
 
-    if ( mCacheCleaner )
-      mCacheCleaner->wait();
-    if ( mIntervalChecker )
-      mIntervalChecker->wait();
-    if ( mItemRetrievalThread )
-      mItemRetrievalThread->wait();
-
     delete mSearchManager;
     mSearchManager = 0;
 
-    for ( int i = 0; i < mConnections.count(); ++i ) {
-      if ( mConnections[ i ] ) {
-        mConnections[ i ]->quit();
-        mConnections[ i ]->wait();
-      }
-    }
+    qDebug() << "terminating connection threads";
+    for ( int i = 0; i < mConnections.count(); ++i )
+      quitThread( mConnections[ i ] );
+    mConnections.clear();
 
     DataStore::self()->close();
+    Q_ASSERT( QSqlDatabase::connectionNames().isEmpty() );
 
-    // execute the deleteLater() calls for the threads so they free their db connections
-    // and the following db termination will work
-    QCoreApplication::instance()->processEvents();
-
+    qDebug() << "stopping db process";
     stopDatabaseProcess();
 
     QSettings settings( XdgBaseDirs::akonadiServerConfigFile(), QSettings::IniFormat );
--- trunk/kdesupport/akonadi/server/src/storage/itemretrievalthread.cpp #933591:933592
@@ -36,7 +36,6 @@
   ItemRetrievalManager *mgr = new ItemRetrievalManager();
   exec();
   delete mgr;
-  deleteLater();
 }
 
 #include "itemretrievalthread.moc"
[prev in list] [next in list] [prev in thread] [next in thread] 

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