+
+ if(thread.needs_work() && !queue.empty())
+ dispatch_work();
+
+ if(do_unload)
+ {
+ MutexLock lock(map_mutex);
+ if(max_retain_frames && frame>=next_unload)
+ {
+ unload_by_age();
+
+ next_unload = frame;
+ for(ResourceMap::iterator i=resources.begin(); i!=resources.end(); ++i)
+ if(i->second.state==ManagedResource::LOADED)
+ next_unload = min(next_unload, i->second.last_used);
+ next_unload = (next_unload<frame ? next_unload+max_retain_frames : 0);
+ }
+
+ if(size_limit)
+ unload_by_size();
+ }
+}
+
+void ResourceManager::dispatch_work()
+{
+ queue.sort(age_order);
+
+ if(queue.front()->last_used+10<frame)
+ {
+ for(LoadQueue::iterator i=queue.begin(); i!=queue.end(); ++i)
+ (*i)->state = ManagedResource::NOT_LOADED;
+ queue.clear();
+ return;
+ }
+
+ while(thread.needs_work() && !queue.empty())