Rename ScriptEngine::wait to match std threading

This commit is contained in:
Zach Pomerantz 2016-05-12 12:45:35 -07:00
parent edf82c57ba
commit 2cc788f98d
3 changed files with 8 additions and 5 deletions

View file

@ -284,8 +284,7 @@ void ScriptEngine::runInThread() {
workerThread->start(); workerThread->start();
} }
void ScriptEngine::waitTillDoneRunning() { void ScriptEngine::wait() {
// If the script never started running or finished running before we got here, we don't need to wait for it
auto workerThread = thread(); auto workerThread = thread();
if (_isThreaded && workerThread) { if (_isThreaded && workerThread) {

View file

@ -197,7 +197,10 @@ protected:
void init(); void init();
QString getFilename() const; QString getFilename() const;
void waitTillDoneRunning();
// Stop any evaluating scripts and wait for the scripting thread to finish.
void wait();
bool evaluatePending() const { return _evaluatesPending > 0; } bool evaluatePending() const { return _evaluatesPending > 0; }
void timerFired(); void timerFired();
void stopAllTimers(); void stopAllTimers();

View file

@ -149,6 +149,7 @@ void ScriptEngines::shutdownScripting() {
// NOTE: typically all script engines are running. But there's at least one known exception to this, the // NOTE: typically all script engines are running. But there's at least one known exception to this, the
// "entities sandbox" which is only used to evaluate entities scripts to test their validity before using // "entities sandbox" which is only used to evaluate entities scripts to test their validity before using
// them. We don't need to stop scripts that aren't running. // them. We don't need to stop scripts that aren't running.
// TODO: Scripts could be shut down faster if we spread them across a threadpool.
if (scriptEngine->isRunning()) { if (scriptEngine->isRunning()) {
qCDebug(scriptengine) << "about to shutdown script:" << scriptName; qCDebug(scriptengine) << "about to shutdown script:" << scriptName;
@ -165,12 +166,12 @@ void ScriptEngines::shutdownScripting() {
// want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing // want any of the scripts final "scriptEnding()" or pending "update()" methods from accessing
// any application state after we leave this stopAllScripts() method // any application state after we leave this stopAllScripts() method
qCDebug(scriptengine) << "waiting on script:" << scriptName; qCDebug(scriptengine) << "waiting on script:" << scriptName;
scriptEngine->waitTillDoneRunning(); scriptEngine->wait();
qCDebug(scriptengine) << "done waiting on script:" << scriptName; qCDebug(scriptengine) << "done waiting on script:" << scriptName;
scriptEngine->deleteLater(); scriptEngine->deleteLater();
// If the script is stopped, we can remove it from our set // Once the script is stopped, we can remove it from our set
i.remove(); i.remove();
} }
} }