code review

This commit is contained in:
Seth Alves 2016-05-20 09:54:54 -07:00
parent 3f5ed4bef8
commit aa58cad93e
3 changed files with 11 additions and 5 deletions

View file

@ -938,6 +938,13 @@ void ScriptEngine::stopAllTimersForEntityScript(const EntityItemID& entityID) {
}
void ScriptEngine::stop() {
_isStopping = true; // this can be done on any thread
// marshal us over to the correct thread
if (QThread::currentThread() != thread()) {
QMetaObject::invokeMethod(this, "stop");
return;
}
if (!_isFinished) {
_isFinished = true;
emit runningStateChanged();

View file

@ -84,7 +84,7 @@ public:
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// NOTE - this is intended to be a public interface for Agent scripts, and local scripts, but not for EntityScripts
Q_INVOKABLE void stop();
Q_INVOKABLE void stop(); // this can be called from any thread
// Stop any evaluating scripts and wait for the scripting thread to finish.
void waitTillDoneRunning();
@ -146,6 +146,8 @@ public:
bool isFinished() const { return _isFinished; } // used by Application and ScriptWidget
bool isRunning() const { return _isRunning; } // used by ScriptWidget
// these are used by code in ScriptEngines.cpp during the "reload all" operation
bool isStopping() const { return _isStopping; }
void setIsStopping() { _isStopping = true; }

View file

@ -160,7 +160,6 @@ void ScriptEngines::shutdownScripting() {
scriptEngine->disconnect(this);
// Gracefully stop the engine's scripting thread
scriptEngine->setIsStopping();
scriptEngine->stop();
// We need to wait for the engine to be done running before we proceed, because we don't
@ -352,8 +351,7 @@ void ScriptEngines::stopAllScripts(bool restart) {
reloadScript(scriptName);
});
}
it.value()->setIsStopping();
QMetaObject::invokeMethod(it.value(), "stop");
it.value()->stop();
qCDebug(scriptengine) << "stopping script..." << it.key();
}
}
@ -376,7 +374,6 @@ bool ScriptEngines::stopScript(const QString& rawScriptURL, bool restart) {
reloadScript(scriptName);
});
}
scriptEngine->setIsStopping();
scriptEngine->stop();
stoppedScript = true;
qCDebug(scriptengine) << "stopping script..." << scriptURL;