Identify files in object cache by filename and optional provided options.
Objects with the same filename may be different from others based on the provided plugin options. Using filename *and* the provided options as object cache key helps to avoid fetching the wrong object.
This commit is contained in:
committed by
Robert Osfield
parent
3816e4c76e
commit
85cd1c456f
@@ -12,6 +12,7 @@
|
||||
*/
|
||||
|
||||
#include <osgDB/ObjectCache>
|
||||
#include <osgDB/Options>
|
||||
|
||||
using namespace osgDB;
|
||||
|
||||
@@ -39,34 +40,48 @@ void ObjectCache::addObjectCache(ObjectCache* objectCache)
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock1(_objectCacheMutex);
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock2(objectCache->_objectCacheMutex);
|
||||
|
||||
// OSG_NOTICE<<"Inserting objects to main ObjectCache "<<objectCache->_objectCache.size()<<std::endl;
|
||||
OSG_DEBUG<<"Inserting objects to main ObjectCache "<<objectCache->_objectCache.size()<<std::endl;
|
||||
|
||||
_objectCache.insert(objectCache->_objectCache.begin(), objectCache->_objectCache.end());
|
||||
}
|
||||
|
||||
|
||||
void ObjectCache::addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp)
|
||||
void ObjectCache::addEntryToObjectCache(const std::string& filename, osg::Object* object, double timestamp, const Options *options)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
_objectCache[filename]=ObjectTimeStampPair(object,timestamp);
|
||||
_objectCache[FileNameOptionsPair(filename, osg::clone(options))] = ObjectTimeStampPair(object,timestamp);
|
||||
OSG_DEBUG<<"Adding "<<filename<<" with options '"<<(options ? options->getOptionString() : "")<<"' to ObjectCache "<<this<<std::endl;
|
||||
}
|
||||
|
||||
osg::Object* ObjectCache::getFromObjectCache(const std::string& fileName)
|
||||
osg::Object* ObjectCache::getFromObjectCache(const std::string& fileName, const Options *options)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
ObjectCacheMap::iterator itr = _objectCache.find(fileName);
|
||||
if (itr!=_objectCache.end()) return itr->second.first.get();
|
||||
ObjectCacheMap::iterator itr = _objectCache.find(FileNameOptionsPair(fileName, options));
|
||||
if (itr!=_objectCache.end())
|
||||
{
|
||||
osg::ref_ptr<const osgDB::Options> o = itr->first.second;
|
||||
if (o.valid())
|
||||
OSG_DEBUG<<"Found "<<fileName<<" with options '"<< o->getOptionString()<< "' in ObjectCache "<<this<<std::endl;
|
||||
else
|
||||
OSG_DEBUG<<"Found "<<fileName<<" in ObjectCache "<<this<<std::endl;
|
||||
return itr->second.first.get();
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
|
||||
osg::ref_ptr<osg::Object> ObjectCache::getRefFromObjectCache(const std::string& fileName)
|
||||
osg::ref_ptr<osg::Object> ObjectCache::getRefFromObjectCache(const std::string& fileName, const Options *options)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
ObjectCacheMap::iterator itr = _objectCache.find(fileName);
|
||||
ObjectCacheMap::iterator itr;
|
||||
itr = _objectCache.find(FileNameOptionsPair(fileName, options));
|
||||
if (itr!=_objectCache.end())
|
||||
{
|
||||
// OSG_NOTICE<<"Found "<<fileName<<" in ObjectCache "<<this<<std::endl;
|
||||
return itr->second.first;
|
||||
osg::ref_ptr<const osgDB::Options> o = itr->first.second;
|
||||
if (o.valid())
|
||||
OSG_DEBUG<<"Found "<<fileName<<" with options '"<< o->getOptionString()<< "' in ObjectCache "<<this<<std::endl;
|
||||
else
|
||||
OSG_DEBUG<<"Found "<<fileName<<" in ObjectCache "<<this<<std::endl;
|
||||
return itr->second.first.get();
|
||||
}
|
||||
else return 0;
|
||||
}
|
||||
@@ -108,10 +123,10 @@ void ObjectCache::removeExpiredObjectsInCache(double expiryTime)
|
||||
}
|
||||
}
|
||||
|
||||
void ObjectCache::removeFromObjectCache(const std::string& fileName)
|
||||
void ObjectCache::removeFromObjectCache(const std::string& fileName, const Options *options)
|
||||
{
|
||||
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_objectCacheMutex);
|
||||
ObjectCacheMap::iterator itr = _objectCache.find(fileName);
|
||||
ObjectCacheMap::iterator itr = _objectCache.find(FileNameOptionsPair(fileName, options));
|
||||
if (itr!=_objectCache.end()) _objectCache.erase(itr);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user