From e9bd289993f87fedd46a3ffc5c6fade043e10df4 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Fri, 1 Feb 2008 00:43:45 +0000 Subject: [PATCH] Keep a list of the currently active pixmap requests (usually one at most), and wait for their finish when closing the document. svn path=/trunk/KDE/kdegraphics/okular/; revision=769281 --- core/document.cpp | 33 ++++++++++++++++++++++++++++++++- core/document_p.h | 5 +++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/core/document.cpp b/core/document.cpp index 4a04e60dc..6008cabf4 100644 --- a/core/document.cpp +++ b/core/document.cpp @@ -615,6 +615,7 @@ void DocumentPrivate::sendGeneratorRequest() // 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 @@ void Document::closeDocument() 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,8 +2614,19 @@ const KComponentData* Document::componentData() const 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() ) @@ -2636,6 +2664,9 @@ void DocumentPrivate::requestDone( PixmapRequest * req ) #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 diff --git a/core/document_p.h b/core/document_p.h index 302bdf803..2347dd65c 100644 --- a/core/document_p.h +++ b/core/document_p.h @@ -26,6 +26,7 @@ #include "fontinfo.h" #include "generator.h" +class QEventLoop; class QTimer; class KTemporaryFile; @@ -70,6 +71,7 @@ class DocumentPrivate m_saveBookmarksTimer( 0 ), m_generator( 0 ), m_generatorsLoaded( false ), + m_closingLoop( 0 ), m_fontsCached( false ) { } @@ -141,6 +143,7 @@ class DocumentPrivate // 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 @@ class DocumentPrivate // cache of the mimetype we support QStringList m_supportedMimeTypes; + QEventLoop *m_closingLoop; + QPointer< FontExtractionThread > m_fontThread; bool m_fontsCached; FontInfo::List m_fontsCache;