From a027cbcd7051c634a51b6029dcb8a5b4bfe8b046 Mon Sep 17 00:00:00 2001 From: Daniel Teske Date: Wed, 14 Oct 2015 11:59:46 +0200 Subject: [PATCH] Fix infinite QWaitCondition:wait() in discardFile*() The original idea was that we would passively wait for another thread to clean up the locker, hence the check-sleep-loop. This was all dandy, except for *also* using the wait condition: this was a) mostly pointless (it would just avoid a few iterations of the wait loop) and b) buggy (if there were no other waiting threads, the actual reader thread wouldn't know that it needs to wake somebody up). As the passive waiting is ugly, we instead fix the use of the wait condition, and do away with the loop. Task-number: QTCREATORBUG-15181 Change-Id: I477dbe7cda49ceca9aa387910d94ad763a43012b Reviewed-by: Oswald Buddenhagen Reviewed-by: Daniel Teske --- src/shared/proparser/qmakeparser.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/shared/proparser/qmakeparser.cpp b/src/shared/proparser/qmakeparser.cpp index 856b703e96e..246afb1d485 100644 --- a/src/shared/proparser/qmakeparser.cpp +++ b/src/shared/proparser/qmakeparser.cpp @@ -63,13 +63,14 @@ void ProFileCache::discardFile(const QString &fileName) if (it != parsed_files.end()) { #ifdef PROPARSER_THREAD_SAFE if (it->locker) { - if (!it->locker->done) + if (!it->locker->done) { + ++it->locker->waiters; it->locker->cond.wait(&mutex); - do { - lck.unlock(); - QThread::sleep(100); - lck.relock(); - } while (it->locker); + if (!--it->locker->waiters) { + delete it->locker; + it->locker = 0; + } + } } #endif if (it->pro) @@ -90,13 +91,14 @@ void ProFileCache::discardFiles(const QString &prefix) if (it.key().startsWith(prefix)) { #ifdef PROPARSER_THREAD_SAFE if (it->locker) { - if (!it->locker->done) + if (!it->locker->done) { + ++it->locker->waiters; it->locker->cond.wait(&mutex); - do { - lck.unlock(); - QThread::sleep(100); - lck.relock(); - } while (it->locker); + if (!--it->locker->waiters) { + delete it->locker; + it->locker = 0; + } + } } #endif if (it->pro) @@ -107,7 +109,6 @@ void ProFileCache::discardFiles(const QString &prefix) } } - ////////// Parser /////////// #define fL1S(s) QString::fromLatin1(s)