OSDN Git Service

make the evaluator (even more) thread-safe
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Fri, 4 Jun 2010 15:08:27 +0000 (17:08 +0200)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>
Fri, 4 Jun 2010 15:57:04 +0000 (17:57 +0200)
the async re-parsing code breaks the assumption that project
parsing only ever starts with a single non-concurrent evaluation
(of the top-level project file), so the population of the base
values in the shared ProFileOption was happily causing crashes.

Reviewed-by: dt
Task-number: QTCREATORBUG-1569

src/plugins/qt4projectmanager/qt4projectmanager.pro
src/shared/proparser/profileevaluator.cpp
src/shared/proparser/profileevaluator.h

index 448067a..f4c492a 100644 (file)
@@ -96,7 +96,7 @@ FORMS += makestep.ui \
     wizards/targetsetuppage.ui
 RESOURCES += qt4projectmanager.qrc \
     wizards/wizards.qrc
-DEFINES += PROPARSER_THREAD_SAFE
+DEFINES += PROPARSER_THREAD_SAFE PROEVALUATOR_THREAD_SAFE
 include(../../shared/proparser/proparser.pri)
 include(qt-s60/qt-s60.pri)
 include(qt-maemo/qt-maemo.pri)
index 0771795..b478890 100644 (file)
@@ -161,6 +161,10 @@ ProFileOption::ProFileOption()
 #endif
 
     cache = 0;
+
+#ifdef PROEVALUATOR_THREAD_SAFE
+    base_inProgress = false;
+#endif
 }
 
 ProFileOption::~ProFileOption()
@@ -1270,7 +1274,21 @@ ProItem::ProItemReturn ProFileEvaluator::Private::visitProFile(ProFile *pro)
 
         if (m_parsePreAndPostFiles) {
 
+#ifdef PROEVALUATOR_THREAD_SAFE
+          {
+            QMutexLocker locker(&m_option->mutex);
+            if (m_option->base_inProgress) {
+                QThreadPool::globalInstance()->releaseThread();
+                m_option->cond.wait(&m_option->mutex);
+                QThreadPool::globalInstance()->reserveThread();
+            } else
+#endif
             if (m_option->base_valuemap.isEmpty()) {
+#ifdef PROEVALUATOR_THREAD_SAFE
+                m_option->base_inProgress = true;
+                locker.unlock();
+#endif
+
                 // ### init QMAKE_QMAKE, QMAKE_SH
                 // ### init QMAKE_EXT_{C,H,CPP,OBJ}
                 // ### init TEMPLATE_PREFIX
@@ -1377,7 +1395,16 @@ ProItem::ProItemReturn ProFileEvaluator::Private::visitProFile(ProFile *pro)
 
                 evaluateFeatureFile(QLatin1String("default_pre.prf"),
                                     &m_option->base_valuemap, &m_option->base_functions);
+
+#ifdef PROEVALUATOR_THREAD_SAFE
+                locker.relock();
+                m_option->base_inProgress = false;
+                m_option->cond.wakeAll();
+#endif
             }
+#ifdef PROEVALUATOR_THREAD_SAFE
+          }
+#endif
 
             m_valuemapStack.top() = m_option->base_valuemap;
 
index e4acafd..57df396 100644 (file)
@@ -182,6 +182,11 @@ struct ProFileOption
     ProFileEvaluator::FunctionDefs base_functions;
     QStringList feature_roots;
     QString qmakespec_name;
+#ifdef PROEVALUATOR_THREAD_SAFE
+    QMutex mutex;
+    QWaitCondition cond;
+    bool base_inProgress;
+#endif
 };
 
 QT_END_NAMESPACE