History

add support to abort evaluation of long running scripts on shutdown

Brad Hefta-Gaub committed 10 years ago

Commit a21bc661 parent 28b5ef62 files · +32 −3Browse files

Showing the changes to libraries/script-engine/src/ScriptEngine.cpp (1 of 2 files). Show all

Unified · Split

libraries/script-engine/src/ScriptEngine.cpp+18−1
@@ -199,11 +199,28 @@ void ScriptEngine::waitTillDoneRunning() { · 198 unmodified lines
199 199
200 // NOTE: waitTillDoneRunning() will be called on the main Application thread, inside of stopAllScripts()200 // NOTE: waitTillDoneRunning() will be called on the main Application thread, inside of stopAllScripts()
201 // we want the application thread to continue to process events, because the scripts will likely need to201 // we want the application thread to continue to process events, because the scripts will likely need to
202 // marshall messages across to the main thread. For example if they access Settings or Meny in any of their202 // marshall messages across to the main thread. For example if they access Settings or Menu in any of their
203 // shutdown code.203 // shutdown code.
204 auto startedWaiting = usecTimestampNow();
204 while (thread()->isRunning()) {205 while (thread()->isRunning()) {
205 // process events for the main application thread, allowing invokeMethod calls to pass between threads206 // process events for the main application thread, allowing invokeMethod calls to pass between threads
206 QCoreApplication::processEvents();207 QCoreApplication::processEvents();
208 auto stillWaiting = usecTimestampNow();
209 auto elapsed = stillWaiting - startedWaiting;
210
211 // if we've been waiting a second or more, then tell the script engine to stop evaluating
212 if (elapsed > USECS_PER_SECOND) {
213 qDebug() << __FUNCTION__ << "...giving up on evaluation elapsed:" << elapsed << "calling abortEvaluation()";
214 abortEvaluation();
215 }
216
217 // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping
218 static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5;
219 if (elapsed > WAITING_TOO_LONG) {
220 qDebug() << __FUNCTION__ << "...giving up on thread elapsed:" << elapsed << "calling thread->quit()";
221 thread()->quit();
222 break;
223 }
207 }224 }
208 }225 }
209}226}