]> git.tdb.fi Git - libs/gl.git/blobdiff - source/resourcemanager.h
Make ResourceManager thread-safe
[libs/gl.git] / source / resourcemanager.h
index f554b3484c7e006006d9b292bc803aea136f9e50..9378d920c9671743daafddfec70def0acee39e68 100644 (file)
@@ -16,6 +16,7 @@ class ResourceWatcher;
 class resource_load_error: public std::runtime_error
 {
 public:
+       resource_load_error(const std::string &, const std::string &);
        resource_load_error(const std::string &, const std::exception &);
        virtual ~resource_load_error() throw() { }
 };
@@ -55,6 +56,7 @@ private:
 
                Resource *resource;
                ResourceLocation location;
+               bool load_priority;
                IO::Seekable *io;
                Resource::AsyncLoader *loader;
                State state;
@@ -112,6 +114,7 @@ private:
 
        LoadingPolicy policy;
        bool async_loads;
+       mutable Mutex map_mutex;
        ResourceMap resources;
        LoadQueue queue;
        UInt64 size_limit;
@@ -132,12 +135,16 @@ public:
        void set_max_retain_frames(unsigned);
 
        void add_resource(Resource &);
-       void *get_data_for_resource(const Resource &);
+private:
+       const ManagedResource &get_managed_resource(const Resource &) const;
+       ManagedResource &get_managed_resource(const Resource &);
+public:
+       void *get_data_for_resource(const Resource &r) { return &get_managed_resource(r); }
        void set_resource_location(Resource &, DataFile::Collection &, const std::string &);
        void set_resource_location(Resource &, const ResourceLocation &);
        const ResourceLocation *get_resource_location(const Resource &) const;
        void load_resource(Resource &);
-       bool is_resource_loaded(const Resource &);
+       bool is_resource_loaded(const Resource &) const;
        void resource_used(const Resource &);
        void remove_resource(Resource &);
 
@@ -149,6 +156,7 @@ private:
        void dispatch_work();
        void unload_by_age();
        void unload_by_size();
+       UInt64 get_total_data_size_() const;
 public:
        UInt64 get_total_data_size() const;