mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 12:23:24 +02:00
Consolidate stoppingAllScripts to ScriptEngines::_stopped
This commit is contained in:
parent
68731973d8
commit
70d0ebb91c
4 changed files with 11 additions and 18 deletions
|
@ -52,8 +52,6 @@
|
|||
|
||||
#include "MIDIEvent.h"
|
||||
|
||||
std::atomic<bool> ScriptEngine::_stoppingAllScripts { false };
|
||||
|
||||
static const QString SCRIPT_EXCEPTION_FORMAT = "[UncaughtException] %1 in %2:%3";
|
||||
|
||||
Q_DECLARE_METATYPE(QScriptEngine::FunctionSignature)
|
||||
|
@ -655,7 +653,7 @@ void ScriptEngine::addEventHandler(const EntityItemID& entityID, const QString&
|
|||
|
||||
|
||||
QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fileName, int lineNumber) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
return QScriptValue(); // bail early
|
||||
}
|
||||
|
||||
|
@ -691,7 +689,7 @@ QScriptValue ScriptEngine::evaluate(const QString& sourceCode, const QString& fi
|
|||
}
|
||||
|
||||
void ScriptEngine::run() {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
return; // bail early - avoid setting state in init(), as evaluate() will bail too
|
||||
}
|
||||
|
||||
|
@ -901,7 +899,7 @@ QObject* ScriptEngine::setupTimerWithInterval(const QScriptValue& function, int
|
|||
}
|
||||
|
||||
QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
qCDebug(scriptengine) << "Script.setInterval() while shutting down is ignored... parent script:" << getFilename();
|
||||
return NULL; // bail early
|
||||
}
|
||||
|
@ -910,7 +908,7 @@ QObject* ScriptEngine::setInterval(const QScriptValue& function, int intervalMS)
|
|||
}
|
||||
|
||||
QObject* ScriptEngine::setTimeout(const QScriptValue& function, int timeoutMS) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
qCDebug(scriptengine) << "Script.setTimeout() while shutting down is ignored... parent script:" << getFilename();
|
||||
return NULL; // bail early
|
||||
}
|
||||
|
@ -962,7 +960,7 @@ void ScriptEngine::print(const QString& message) {
|
|||
// If no callback is specified, the included files will be loaded synchronously and will block execution until
|
||||
// all of the files have finished loading.
|
||||
void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callback) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
qCDebug(scriptengine) << "Script.include() while shutting down is ignored..."
|
||||
<< "includeFiles:" << includeFiles << "parent script:" << getFilename();
|
||||
return; // bail early
|
||||
|
@ -1063,7 +1061,7 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
|
|||
}
|
||||
|
||||
void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
qCDebug(scriptengine) << "Script.include() while shutting down is ignored... "
|
||||
<< "includeFile:" << includeFile << "parent script:" << getFilename();
|
||||
return; // bail early
|
||||
|
@ -1078,7 +1076,7 @@ void ScriptEngine::include(const QString& includeFile, QScriptValue callback) {
|
|||
// as a stand-alone script. To accomplish this, the ScriptEngine class just emits a signal which
|
||||
// the Application or other context will connect to in order to know to actually load the script
|
||||
void ScriptEngine::load(const QString& loadFile) {
|
||||
if (_stoppingAllScripts) {
|
||||
if (DependencyManager::get<ScriptEngines>()->_stopped) {
|
||||
qCDebug(scriptengine) << "Script.load() while shutting down is ignored... "
|
||||
<< "loadFile:" << loadFile << "parent script:" << getFilename();
|
||||
return; // bail early
|
||||
|
|
|
@ -222,9 +222,6 @@ protected:
|
|||
QUrl currentSandboxURL {}; // The toplevel url string for the entity script that loaded the code being executed, else empty.
|
||||
void doWithEnvironment(const EntityItemID& entityID, const QUrl& sandboxURL, std::function<void()> operation);
|
||||
void callWithEnvironment(const EntityItemID& entityID, const QUrl& sandboxURL, QScriptValue function, QScriptValue thisObject, QScriptValueList args);
|
||||
|
||||
friend class ScriptEngines;
|
||||
static std::atomic<bool> _stoppingAllScripts;
|
||||
};
|
||||
|
||||
#endif // hifi_ScriptEngine_h
|
||||
|
|
|
@ -118,7 +118,7 @@ void ScriptEngines::registerScriptInitializer(ScriptInitializer initializer) {
|
|||
}
|
||||
|
||||
void ScriptEngines::addScriptEngine(ScriptEngine* engine) {
|
||||
if (!_stoppingAllScripts) {
|
||||
if (!_stopped) {
|
||||
QMutexLocker locker(&_allScriptsMutex);
|
||||
_allKnownScriptEngines.insert(engine);
|
||||
}
|
||||
|
@ -128,15 +128,14 @@ void ScriptEngines::removeScriptEngine(ScriptEngine* engine) {
|
|||
// If we're not already in the middle of stopping all scripts, then we should remove ourselves
|
||||
// from the list of running scripts. We don't do this if we're in the process of stopping all scripts
|
||||
// because that method removes scripts from its list as it iterates them
|
||||
if (!_stoppingAllScripts) {
|
||||
if (!_stopped) {
|
||||
QMutexLocker locker(&_allScriptsMutex);
|
||||
_allKnownScriptEngines.remove(engine);
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptEngines::shutdownScripting() {
|
||||
_stoppingAllScripts = true;
|
||||
ScriptEngine::_stoppingAllScripts = true;
|
||||
_stopped = true;
|
||||
QMutexLocker locker(&_allScriptsMutex);
|
||||
qCDebug(scriptengine) << "Stopping all scripts.... currently known scripts:" << _allKnownScriptEngines.size();
|
||||
|
||||
|
|
|
@ -87,17 +87,16 @@ protected:
|
|||
void onScriptEngineError(const QString& scriptFilename);
|
||||
void launchScriptEngine(ScriptEngine* engine);
|
||||
|
||||
|
||||
Setting::Handle<bool> _firstRun { "firstRun", true };
|
||||
QReadWriteLock _scriptEnginesHashLock;
|
||||
QHash<QUrl, ScriptEngine*> _scriptEnginesHash;
|
||||
QSet<ScriptEngine*> _allKnownScriptEngines;
|
||||
QMutex _allScriptsMutex;
|
||||
std::atomic<bool> _stoppingAllScripts { false };
|
||||
std::list<ScriptInitializer> _scriptInitializers;
|
||||
mutable Setting::Handle<QString> _scriptsLocationHandle;
|
||||
ScriptsModel _scriptsModel;
|
||||
ScriptsModelFilter _scriptsModelFilter;
|
||||
std::atomic<bool> _stopped { false };
|
||||
};
|
||||
|
||||
QUrl normalizeScriptURL(const QUrl& rawScriptURL);
|
||||
|
|
Loading…
Reference in a new issue