Added "serialize" and plugin "preload" options in the "read-threads" code path.

This commit is contained in:
Robert Osfield 2008-09-23 15:41:49 +00:00
parent 1b02cf99dc
commit edc966c4c2
3 changed files with 72 additions and 3 deletions

View File

@ -18,7 +18,10 @@
#include <osg/Referenced>
#include <osgDB/ReadFile>
#include <osgDB/Registry>
#include <OpenThreads/Thread>
#include <OpenThreads/ScopedLock>
struct OSG_EXPORT RefBarrier : public osg::Referenced, public OpenThreads::Barrier
{
@ -104,12 +107,76 @@ public:
osg::ref_ptr<RefBarrier> _endBarrier;
};
void runMultiThreadReadTests(int numThreads)
class SerializerReadFileCallback : public osgDB::Registry::ReadFileCallback
{
public:
virtual osgDB::ReaderWriter::ReadResult openArchive(const std::string& filename,osgDB::ReaderWriter::ArchiveStatus status, unsigned int indexBlockSizeHint, const osgDB::ReaderWriter::Options* useObjectCache)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->openArchiveImplementation(filename, status, indexBlockSizeHint, useObjectCache);
}
virtual osgDB::ReaderWriter::ReadResult readObject(const std::string& filename, const osgDB::ReaderWriter::Options* options)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->readObjectImplementation(filename,options);
}
virtual osgDB::ReaderWriter::ReadResult readImage(const std::string& filename, const osgDB::ReaderWriter::Options* options)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->readImageImplementation(filename,options);
}
virtual osgDB::ReaderWriter::ReadResult readHeightField(const std::string& filename, const osgDB::ReaderWriter::Options* options)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->readHeightFieldImplementation(filename,options);
}
virtual osgDB::ReaderWriter::ReadResult readNode(const std::string& filename, const osgDB::ReaderWriter::Options* options)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->readNodeImplementation(filename,options);
}
virtual osgDB::ReaderWriter::ReadResult readShader(const std::string& filename, const osgDB::ReaderWriter::Options* options)
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_mutex);
return osgDB::Registry::instance()->readShaderImplementation(filename,options);
}
protected:
virtual ~SerializerReadFileCallback() {}
OpenThreads::Mutex _mutex;
};
void runMultiThreadReadTests(int numThreads, osg::ArgumentParser& arguments)
{
#if VERBOSE
osg::notify(osg::NOTICE)<<"runMultiThreadReadTests() -- running"<<std::endl;
#endif
if (arguments.read("preload"))
{
osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("osg"));
osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("rgb"));
osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("jpeg"));
osgDB::Registry::instance()->loadLibrary(osgDB::Registry::instance()->createLibraryNameForExtension("ive"));
}
if (arguments.read("serialize"))
{
osgDB::Registry::instance()->setReadFileCallback(new SerializerReadFileCallback());
}
osg::ref_ptr<RefBarrier> startBarrier = new RefBarrier(numThreads+1);
osg::ref_ptr<RefBarrier> endBarrier = new RefBarrier(numThreads+1);

View File

@ -21,6 +21,8 @@
#ifndef MULTITHREADEDREAD_H
#define MULTITHREADEDREAD_H 1
extern void runMultiThreadReadTests(int numThreads);
#include <osg/ArgumentParser>
extern void runMultiThreadReadTests(int numThreads, osg::ArgumentParser& arguments);
#endif

View File

@ -628,7 +628,7 @@ int main( int argc, char** argv )
if (numReadThreads>0)
{
runMultiThreadReadTests(numReadThreads);
runMultiThreadReadTests(numReadThreads, arguments);
return 0;
}