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

List:       kde-commits
Subject:    KDE/kdegraphics/okular/core
From:       Pino Toscano <toscano.pino () tiscali ! it>
Date:       2008-02-01 0:43:46
Message-ID: 1201826626.536238.1986.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 769281 by pino:

Keep a list of the currently active pixmap requests (usually one at most), and wait \
for their finish when closing the document.


 M  +32 -1     document.cpp  
 M  +5 -0      document_p.h  


--- trunk/KDE/kdegraphics/okular/core/document.cpp #769280:769281
@@ -615,6 +615,7 @@
         // we always have to unlock _before_ the generatePixmap() because
         // a sync generation would end with requestDone() -> deadlock, and
         // we can not really know if the generator can do async requests
+        m_executingPixmapRequests.push_back( request );
         m_pixmapRequestsMutex.unlock();
         m_generator->generatePixmap( request );
     }
@@ -1313,6 +1314,22 @@
     if ( !d->m_generator )
         return;
 
+    QEventLoop loop;
+    bool startEventLoop = false;
+    do
+    {
+        d->m_pixmapRequestsMutex.lock();
+        startEventLoop = !d->m_executingPixmapRequests.isEmpty();
+        d->m_pixmapRequestsMutex.unlock();
+        if ( startEventLoop )
+        {
+            d->m_closingLoop = &loop;
+            loop.exec();
+            d->m_closingLoop = 0;
+        }
+    }
+    while ( startEventLoop );
+
     if ( d->m_fontThread )
     {
         disconnect( d->m_fontThread, 0, this, 0 );
@@ -2597,9 +2614,20 @@
 
 void DocumentPrivate::requestDone( PixmapRequest * req )
 {
-    if ( !m_generator || !req )
+    if ( !req )
         return;
 
+    if ( !m_generator || m_closingLoop )
+    {
+        m_pixmapRequestsMutex.lock();
+        m_executingPixmapRequests.removeAll( req );
+        m_pixmapRequestsMutex.unlock();
+        delete req;
+        if ( m_closingLoop )
+            m_closingLoop->exit();
+        return;
+    }
+
 #ifndef NDEBUG
     if ( !m_generator->canGeneratePixmap() )
         kDebug(OkularDebug) << "requestDone with generator not in READY state.";
@@ -2636,6 +2664,9 @@
 #endif
 
     // 3. delete request
+    m_pixmapRequestsMutex.lock();
+    m_executingPixmapRequests.removeAll( req );
+    m_pixmapRequestsMutex.unlock();
     delete req;
 
     // 4. start a new generation if some is pending
--- trunk/KDE/kdegraphics/okular/core/document_p.h #769280:769281
@@ -26,6 +26,7 @@
 #include "fontinfo.h"
 #include "generator.h"
 
+class QEventLoop;
 class QTimer;
 class KTemporaryFile;
 
@@ -70,6 +71,7 @@
             m_saveBookmarksTimer( 0 ),
             m_generator( 0 ),
             m_generatorsLoaded( false ),
+            m_closingLoop( 0 ),
             m_fontsCached( false )
         {
         }
@@ -141,6 +143,7 @@
         // observers / requests / allocator stuff
         QMap< int, DocumentObserver * > m_observers;
         QLinkedList< PixmapRequest * > m_pixmapRequestsStack;
+        QLinkedList< PixmapRequest * > m_executingPixmapRequests;
         QMutex m_pixmapRequestsMutex;
         QLinkedList< AllocatedPixmap * > m_allocatedPixmapsFifo;
         qulonglong m_allocatedPixmapsTotalMemory;
@@ -176,6 +179,8 @@
         // cache of the mimetype we support
         QStringList m_supportedMimeTypes;
 
+        QEventLoop *m_closingLoop;
+
         QPointer< FontExtractionThread > m_fontThread;
         bool m_fontsCached;
         FontInfo::List m_fontsCache;


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

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