History

Make script cache thread safe

Brad Davis committed 10 years ago

Commit ee017cf1 parent f97e61e2 files · +42 −12Browse files

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

Unified · Split

libraries/script-engine/src/ScriptCache.h+5−0
@@ -12,6 +12,7 @@ · 11 unmodified lines
12#ifndef hifi_ScriptCache_h12#ifndef hifi_ScriptCache_h
13#define hifi_ScriptCache_h13#define hifi_ScriptCache_h
14 14
15#include <mutex>
15#include <ResourceCache.h>16#include <ResourceCache.h>
16 17
17class ScriptUser {18class ScriptUser {
@@ -27,6 +28,9 @@ class ScriptCache : public QObject, public Dependency { · 9 unmodified lines
27 Q_OBJECT28 Q_OBJECT
28 SINGLETON_DEPENDENCY29 SINGLETON_DEPENDENCY
29 30
31 using Mutex = std::mutex;
32 using Lock = std::unique_lock<Mutex>;
33
30public:34public:
31 void clearCache();35 void clearCache();
32 void getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload = false);36 void getScriptContents(const QString& scriptOrURL, contentAvailableCallback contentAvailable, bool forceDownload = false);
@@ -46,6 +50,7 @@ private slots: · 13 unmodified lines
46private:50private:
47 ScriptCache(QObject* parent = NULL);51 ScriptCache(QObject* parent = NULL);
48 52
53 Mutex _containerLock;
49 QMultiMap<QUrl, contentAvailableCallback> _contentCallbacks;54 QMultiMap<QUrl, contentAvailableCallback> _contentCallbacks;
50 55
51 QHash<QUrl, QString> _scriptCache;56 QHash<QUrl, QString> _scriptCache;