Skip to content

Commit

Permalink
scide: prevent UI freeze when language is posting extensively after s…
Browse files Browse the repository at this point in the history
…top request

fixes #614

Signed-off-by: Tim Blechmann <tim@klingt.org>
(cherry picked from commit 0e47b83)
  • Loading branch information
timblechmann committed Oct 25, 2012
1 parent 13c7f9d commit 190d7c2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
13 changes: 12 additions & 1 deletion editors/sc-ide/core/sc_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ ScProcess::ScProcess( Settings::Manager * settings, QObject * parent ):
QProcess( parent ),
mIpcServer( new QLocalServer(this) ),
mIpcSocket(NULL),
mIpcServerName("SCIde_" + QString::number(QCoreApplication::applicationPid()))
mIpcServerName("SCIde_" + QString::number(QCoreApplication::applicationPid())),
mTerminationRequested(false)
{
mIntrospectionParser = new ScIntrospectionParser( this );
mIntrospectionParser->start();
Expand Down Expand Up @@ -172,6 +173,9 @@ void ScProcess::stopLanguage (void)

closeWriteChannel();

mTerminationRequested = true;
mTerminationRequestTime = QDateTime::currentDateTimeUtc();

bool finished = waitForFinished(200);
if ( !finished && (state() != QProcess::NotRunning) ) {
#ifdef Q_OS_WIN32
Expand All @@ -183,6 +187,7 @@ void ScProcess::stopLanguage (void)
if (!reallyFinished)
emit statusMessage(tr("Failed to stop interpreter!"));
}
mTerminationRequested = false;
}

void ScProcess::restartLanguage()
Expand All @@ -195,6 +200,12 @@ void ScProcess::restartLanguage()

void ScProcess::onReadyRead(void)
{
if (mTerminationRequested) {
// when stopping the language, we don't want to post for longer than 200 ms to prevent the UI to freeze
if (QDateTime::currentDateTimeUtc().toMSecsSinceEpoch() - mTerminationRequestTime.toMSecsSinceEpoch() > 200)
return;
}

QByteArray out = QProcess::readAll();
QString postString = QString::fromUtf8(out);
emit scPost(postString);
Expand Down
3 changes: 3 additions & 0 deletions editors/sc-ide/core/sc_process.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

#include <QAction>
#include <QByteArray>
#include <QDateTime>
#include <QDebug>
#include <QProcess>
#include <QThread>
Expand Down Expand Up @@ -125,6 +126,8 @@ private slots:
QByteArray mIpcData;

QString mCurrentDocumentPath;
bool mTerminationRequested;
QDateTime mTerminationRequestTime;
};

class ScRequest : public QObject
Expand Down

0 comments on commit 190d7c2

Please sign in to comment.