use a mutex to avoid a smaller race

This commit is contained in:
Seth Alves 2016-11-10 17:12:06 -08:00
parent aef39ce6fa
commit 576eed9941
2 changed files with 13 additions and 9 deletions

View file

@ -1214,16 +1214,19 @@ void ScriptEngine::include(const QStringList& includeFiles, QScriptValue callbac
QString contents = data[url];
if (contents.isNull()) {
qCDebug(scriptengine) << "Error loading file: " << url << "line:" << __LINE__;
} else if (!_includedURLs.contains(url)) {
_includedURLs << url;
// Set the parent url so that path resolution will be relative
// to this script's url during its initial evaluation
_parentURL = url.toString();
auto operation = [&]() {
evaluate(contents, url.toString());
};
} else {
std::lock_guard<std::recursive_mutex> lock(_lock);
if (!_includedURLs.contains(url)) {
_includedURLs << url;
// Set the parent url so that path resolution will be relative
// to this script's url during its initial evaluation
_parentURL = url.toString();
auto operation = [&]() {
evaluate(contents, url.toString());
};
doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
doWithEnvironment(capturedEntityIdentifier, capturedSandboxURL, operation);
}
}
}
_parentURL = parentURL;

View file

@ -245,6 +245,7 @@ protected:
std::function<bool()> _emitScriptUpdates{ [](){ return true; } };
std::recursive_mutex _lock;
};
#endif // hifi_ScriptEngine_h