diff options
author | Martin Jones <martin.jones@nokia.com> | 2010-03-29 05:33:24 (GMT) |
---|---|---|
committer | Martin Jones <martin.jones@nokia.com> | 2010-03-29 05:33:24 (GMT) |
commit | 7f01d8851f912051b35af7dd078372c9970d45fe (patch) | |
tree | d058bd970d1d059976833459dcf1457bb889012d /src/declarative/util/qdeclarativepixmapcache.cpp | |
parent | 863888382ec5a84b95b765731f702fcb597b8a4d (diff) | |
download | Qt-7f01d8851f912051b35af7dd078372c9970d45fe.zip Qt-7f01d8851f912051b35af7dd078372c9970d45fe.tar.gz Qt-7f01d8851f912051b35af7dd078372c9970d45fe.tar.bz2 |
Make sure the image reader thread is shutdown properly
Prevents deadlock on shutdown for very shortlived runs,
e.g. autotests
Diffstat (limited to 'src/declarative/util/qdeclarativepixmapcache.cpp')
-rw-r--r-- | src/declarative/util/qdeclarativepixmapcache.cpp | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/src/declarative/util/qdeclarativepixmapcache.cpp b/src/declarative/util/qdeclarativepixmapcache.cpp index 1d90bf8..fe5863f 100644 --- a/src/declarative/util/qdeclarativepixmapcache.cpp +++ b/src/declarative/util/qdeclarativepixmapcache.cpp @@ -114,6 +114,7 @@ private: QList<QDeclarativePixmapReply*> cancelled; QDeclarativeEngine *engine; QDeclarativeImageRequestHandler *handler; + QWaitCondition started; QMutex mutex; static QHash<QDeclarativeEngine *,QDeclarativeImageReader*> readers; @@ -370,8 +371,15 @@ QDeclarativeImageReader::~QDeclarativeImageReader() readers.remove(engine); readerMutex.unlock(); - quit(); - wait(); + if (isRunning()) { + quit(); + while (!wait(100)) { + // It is possible to for the quit to happen before exec() + // Need to wait until the event loop starts so that we + // can stop it. Particularly likely with an idle thread. + quit(); + } + } } QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *engine) @@ -380,6 +388,7 @@ QDeclarativeImageReader *QDeclarativeImageReader::instance(QDeclarativeEngine *e QDeclarativeImageReader *reader = readers.value(engine); if (!reader) { reader = new QDeclarativeImageReader(engine); + reader->started.wait(&readerMutex); readers.insert(engine, reader); } readerMutex.unlock(); @@ -414,7 +423,10 @@ void QDeclarativeImageReader::cancel(QDeclarativePixmapReply *reply) void QDeclarativeImageReader::run() { + readerMutex.lock(); handler = new QDeclarativeImageRequestHandler(this, engine); + started.wakeAll(); + readerMutex.unlock(); exec(); |