History

more work on proper threading of ScriptEngine

Brad Hefta-Gaub committed 11 years ago

Commit a3c02881 parent 18fbf896 files · +151 −116Browse files

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

Unified · Split

libraries/script-engine/src/ScriptCache.cpp+15−2
@@ -15,6 +15,7 @@ · 14 unmodified lines
1515 #include <QNetworkConfiguration>
1616 #include <QNetworkReply>
1717 #include <QObject>
18+#include <QThread>
1819
1920 #include <assert.h>
2021 #include <SharedUtil.h>
@@ -42,7 +43,7 @@ QString ScriptCache::getScript(const QUrl& unnormalizedURL, ScriptUser* scriptUs · 21 unmodified lines
4243 if (alreadyWaiting) {
4344 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();
4445 } else {
45− auto request = ResourceManager::createResourceRequest(this, url);
46+ auto request = ResourceManager::createResourceRequest(nullptr, url);
4647 request->setCacheEnabled(!reload);
4748 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptDownloaded);
4849 request->send();
@@ -82,6 +83,9 @@ void ScriptCache::scriptDownloaded() { · 33 unmodified lines
8283 }
8384
8485 void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload) {
86+ #ifdef THREAD_DEBUGGING
87+ qCDebug(scriptengine) << "ScriptCache::getScriptContents() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
88+ #endif
8589 QUrl unnormalizedURL(scriptOrURL);
8690 QUrl url = ResourceManager::normalizeURL(unnormalizedURL);
8791
@@ -93,6 +97,9 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 5 unmodified lines
9397
9498 if (_scriptCache.contains(url) && !forceDownload) {
9599 qCDebug(scriptengine) << "Found script in cache:" << url.toString();
100+ #if 1 // def THREAD_DEBUGGING
101+ qCDebug(scriptengine) << "ScriptCache::getScriptContents() about to call contentAvailable() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
102+ #endif
96103 contentAvailable(url.toString(), _scriptCache[url], true, true);
97104 } else {
98105 bool alreadyWaiting = _contentCallbacks.contains(url);
@@ -101,7 +108,10 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 2 unmodified lines
101108 if (alreadyWaiting) {
102109 qCDebug(scriptengine) << "Already downloading script at:" << url.toString();
103110 } else {
104− auto request = ResourceManager::createResourceRequest(this, url);
111+ #ifdef THREAD_DEBUGGING
112+ qCDebug(scriptengine) << "about to call: ResourceManager::createResourceRequest(this, url); on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
113+ #endif
114+ auto request = ResourceManager::createResourceRequest(nullptr, url);
105115 request->setCacheEnabled(!forceDownload);
106116 connect(request, &ResourceRequest::finished, this, &ScriptCache::scriptContentAvailable);
107117 request->send();
@@ -110,6 +120,9 @@ void ScriptCache::getScriptContents(const QString& scriptOrURL, contentAvailable · 2 unmodified lines
110120 }
111121
112122 void ScriptCache::scriptContentAvailable() {
123+ #ifdef THREAD_DEBUGGING
124+ qCDebug(scriptengine) << "ScriptCache::scriptContentAvailable() on thread [" << QThread::currentThread() << "] expected thread [" << thread() << "]";
125+ #endif
113126 ResourceRequest* req = qobject_cast<ResourceRequest*>(sender());
114127 QUrl url = req->getUrl();
115128 QList<contentAvailableCallback> allCallbacks = _contentCallbacks.values(url);