From a2e9fadb61c909e46146fb4dbd31eabe6edd6e89 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Mon, 5 Sep 2011 14:07:27 +0200
Subject: [PATCH] QmlProfilerTool: Fix hang on exit

the reader thread has to terminate on its own, terminate
is not reliable.

Change-Id: I4222bc8f0c585c190cd90efbaade0b03ca698ec7
Reviewed-on: http://codereview.qt.nokia.com/4194
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Aurindam Jana <aurindam.jana@nokia.com>
---
 src/tools/qmlprofilertool/commandlistener.cpp  |  7 ++++++-
 src/tools/qmlprofilertool/constants.h          | 18 ++++++++++++++++++
 src/tools/qmlprofilertool/main.cpp             |  3 ++-
 .../qmlprofilertool/qmlprofilerapplication.cpp | 11 ++++++++---
 src/tools/qmlprofilertool/qmlprofilertool.pro  |  4 +++-
 5 files changed, 37 insertions(+), 6 deletions(-)
 create mode 100644 src/tools/qmlprofilertool/constants.h

diff --git a/src/tools/qmlprofilertool/commandlistener.cpp b/src/tools/qmlprofilertool/commandlistener.cpp
index eb06a35a7f0..1f23ea0b954 100644
--- a/src/tools/qmlprofilertool/commandlistener.cpp
+++ b/src/tools/qmlprofilertool/commandlistener.cpp
@@ -31,6 +31,7 @@
 **************************************************************************/
 
 #include "commandlistener.h"
+#include "constants.h"
 #include <QTextStream>
 
 CommandListener::CommandListener(QObject *parent)
@@ -46,7 +47,11 @@ void CommandListener::run()
     do {
         line = in.readLine();
         line = line.trimmed();
-        if (!line.isEmpty())
+        if (!line.isEmpty()) {
             emit command(line);
+            if (line == QLatin1String(Constants::CMD_QUIT)
+                    || line == QLatin1String(Constants::CMD_QUIT2))
+                return;
+        }
     } while (!m_stopRequested && !line.isNull());
 }
diff --git a/src/tools/qmlprofilertool/constants.h b/src/tools/qmlprofilertool/constants.h
new file mode 100644
index 00000000000..fa942d8ae22
--- /dev/null
+++ b/src/tools/qmlprofilertool/constants.h
@@ -0,0 +1,18 @@
+#ifndef CONSTANTS_H
+#define CONSTANTS_H
+
+namespace Constants {
+
+const char * const CMD_HELP ="help";
+const char * const CMD_HELP2 = "h";
+const char * const CMD_HELP3 = "?";
+
+const char * const CMD_RECORD ="record";
+const char * const CMD_RECORD2 ="r";
+
+const char * const CMD_QUIT ="quit";
+const char * const CMD_QUIT2 = "q";
+
+}
+
+#endif // CONSTANTS_H
diff --git a/src/tools/qmlprofilertool/main.cpp b/src/tools/qmlprofilertool/main.cpp
index 9b03ad8adf2..04287c167d5 100644
--- a/src/tools/qmlprofilertool/main.cpp
+++ b/src/tools/qmlprofilertool/main.cpp
@@ -47,8 +47,9 @@ int main(int argc, char *argv[])
     listener.start();
 
     int exitValue = app.exec();
-    listener.terminate();
+    // wait for listener to exit
     listener.wait();
 
+
     return exitValue;
 }
diff --git a/src/tools/qmlprofilertool/qmlprofilerapplication.cpp b/src/tools/qmlprofilertool/qmlprofilerapplication.cpp
index 8e8be8715b1..6261f64ad0f 100644
--- a/src/tools/qmlprofilertool/qmlprofilerapplication.cpp
+++ b/src/tools/qmlprofilertool/qmlprofilerapplication.cpp
@@ -31,6 +31,7 @@
 **************************************************************************/
 
 #include "qmlprofilerapplication.h"
+#include "constants.h"
 #include <utils/qtcassert.h>
 #include <QtCore/QStringList>
 #include <QtCore/QTextStream>
@@ -204,11 +205,15 @@ QString QmlProfilerApplication::traceFileName() const
 void QmlProfilerApplication::userCommand(const QString &command)
 {
     QString cmd = command.trimmed();
-    if (cmd == "help" || cmd == "h" || cmd == "?") {
+    if (cmd == Constants::CMD_HELP
+            || cmd == Constants::CMD_HELP2
+            || cmd == Constants::CMD_HELP3) {
         printCommands();
-    } else if (cmd == "r" || cmd == "record") {
+    } else if (cmd == Constants::CMD_RECORD
+               || cmd == Constants::CMD_RECORD2) {
         m_traceClient.setRecording(!m_traceClient.isRecording());
-    } else if (cmd == "q" || cmd == "quit") {
+    } else if (cmd == Constants::CMD_QUIT
+               || cmd == Constants::CMD_QUIT2) {
         if (m_traceClient.isRecording()) {
             m_quitAfterSave = true;
             m_traceClient.setRecording(false);
diff --git a/src/tools/qmlprofilertool/qmlprofilertool.pro b/src/tools/qmlprofilertool/qmlprofilertool.pro
index 3e15c56d2d0..4e9b4abaae4 100644
--- a/src/tools/qmlprofilertool/qmlprofilertool.pro
+++ b/src/tools/qmlprofilertool/qmlprofilertool.pro
@@ -19,6 +19,8 @@ SOURCES += main.cpp \
 
 HEADERS += \
     qmlprofilerapplication.h \
-    commandlistener.h
+    commandlistener.h \
+    constants.h
+
 
 
-- 
GitLab