History

more CR feedback

Brad Hefta-Gaub committed 10 years ago

Commit 45690321 parent 6026e052 files · +7 −17Browse 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+7−16
@@ -195,14 +195,6 @@ void ScriptEngine::runInThread() { · 194 unmodified lines
195 workerThread->start();195 workerThread->start();
196}196}
197 197
198void ScriptEngine::threadSafeAbortEvaluation() {
199 if (QThread::currentThread() != thread()) {
200 QMetaObject::invokeMethod(this, "threadSafeAbortEvaluation");
201 return;
202 }
203 abortEvaluation();
204}
205
206void ScriptEngine::waitTillDoneRunning() {198void ScriptEngine::waitTillDoneRunning() {
207 // If the script never started running or finished running before we got here, we don't need to wait for it199 // If the script never started running or finished running before we got here, we don't need to wait for it
208 if (_isRunning && _isThreaded) {200 if (_isRunning && _isThreaded) {
@@ -218,21 +210,20 @@ void ScriptEngine::waitTillDoneRunning() { · 9 unmodified lines
218 // process events for the main application thread, allowing invokeMethod calls to pass between threads210 // process events for the main application thread, allowing invokeMethod calls to pass between threads
219 QCoreApplication::processEvents();211 QCoreApplication::processEvents();
220 auto stillWaiting = usecTimestampNow();212 auto stillWaiting = usecTimestampNow();
221 auto elapsed = stillWaiting - startedWaiting;213 auto elapsedUsecs = stillWaiting - startedWaiting;
222 214
223 // if we've been waiting a second or more, then tell the script engine to stop evaluating215 // if we've been waiting a second or more, then tell the script engine to stop evaluating
224 static const auto MAX_SCRIPT_EVALUATION_TIME = USECS_PER_SECOND;216 static const auto MAX_SCRIPT_EVALUATION_TIME = USECS_PER_SECOND;
225 if (elapsed > MAX_SCRIPT_EVALUATION_TIME) {217 static const auto WAITING_TOO_LONG = MAX_SCRIPT_EVALUATION_TIME * 5;
226 qCDebug(scriptengine) << "Script " << scriptName << " has been running too long [" << elapsed << "] aborting evaluation.";
227 threadSafeAbortEvaluation();
228 }
229 218
230 // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping219 // if we've been waiting for more than 5 seconds then we should be more aggessive about stopping
231 static const auto WAITING_TOO_LONG = USECS_PER_SECOND * 5;220 if (elapsedUsecs > WAITING_TOO_LONG) {
232 if (elapsed > WAITING_TOO_LONG) {221 qCDebug(scriptengine) << "Script " << scriptName << " has been running too long [" << elapsedUsecs << "] quitting.";
233 qCDebug(scriptengine) << "Script " << scriptName << " has been running too long [" << elapsed << "] quitting.";
234 thread()->quit();222 thread()->quit();
235 break;223 break;
224 } else if (elapsedUsecs > MAX_SCRIPT_EVALUATION_TIME) {
225 qCDebug(scriptengine) << "Script " << scriptName << " has been running too long [" << elapsedUsecs << "] aborting evaluation.";
226 QMetaObject::invokeMethod(this, "abortEvaluation");
236 }227 }
237 }228 }
238 }229 }