X-Git-Url: http://git.tdb.fi/?p=libs%2Fgl.git;a=blobdiff_plain;f=source%2Fresourcemanager.h;h=a1ff7aee2fc32adda60d12b0a63166c635e81822;hp=244c67ec29cc5acda96ea303bddda0f7583cf1ee;hb=d184ad8a88156a5b0cfe926e5aa66fd574556560;hpb=946266e823c07025f115b5e4f5523b496dcb393e diff --git a/source/resourcemanager.h b/source/resourcemanager.h index 244c67ec..a1ff7aee 100644 --- a/source/resourcemanager.h +++ b/source/resourcemanager.h @@ -26,11 +26,12 @@ public: private: struct ManagedResource { - enum ResourceState + enum State { NOT_LOADED, LOAD_QUEUED, LOADING, + LOAD_FINISHED, LOADED }; @@ -39,7 +40,7 @@ private: std::string name; IO::Seekable *io; Resource::AsyncLoader *loader; - ResourceState state; + State state; unsigned last_used; UInt64 data_size; std::vector watchers; @@ -47,6 +48,8 @@ private: ManagedResource(Resource &); void start_loading(); + bool process(bool); + void finish_loading(bool); void finish_loading(); void unload(); @@ -54,41 +57,40 @@ private: void remove_watcher(ResourceWatcher &); }; + typedef std::list LoadQueue; + class LoadingThread: public Thread { - public: - enum State - { - IDLE, - SYNC_PENDING, - BUSY, - LOAD_FINISHED, - TERMINATING - }; - private: - ResourceManager &manager; Semaphore sem; - ManagedResource *volatile resource; - volatile State state; + Mutex queue_mutex; + LoadQueue async_queue; + LoadQueue sync_queue; + unsigned capacity; + unsigned size; + volatile bool done; public: - LoadingThread(ResourceManager &); + LoadingThread(); private: virtual void main(); + ManagedResource *front(LoadQueue &); + public: - void set_resource(ManagedResource *); - ManagedResource *get_resource() const { return resource; } - void sync(); - State get_state() const { return state; } + void add_resource(ManagedResource &); + void remove_resource(ManagedResource &); + private: + bool try_remove_resource(ManagedResource &); + public: + bool sync(); + bool needs_work() const { return size ResourceMap; - typedef std::list LoadQueue; LoadingPolicy policy; bool async_loads; @@ -122,7 +124,15 @@ public: void unwatch_resource(const Resource &, ResourceWatcher &); void tick(); +private: + void dispatch_work(); + void unload_by_age(); + void unload_by_size(); +public: UInt64 get_total_data_size() const; + +private: + static bool age_order(ManagedResource *, ManagedResource *); }; } // namespace GL