From edc966c4c2852223be3e9c93e90e65471c619ea0 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 23 Sep 2008 15:41:49 +0000 Subject: [PATCH] Added "serialize" and plugin "preload" options in the "read-threads" code path. --- examples/osgunittests/MultiThreadRead.cpp | 69 ++++++++++++++++++++++- examples/osgunittests/MultiThreadRead.h | 4 +- examples/osgunittests/osgunittests.cpp | 2 +- 3 files changed, 72 insertions(+), 3 deletions(-) diff --git a/examples/osgunittests/MultiThreadRead.cpp b/examples/osgunittests/MultiThreadRead.cpp index b1bf08984..88b490639 100644 --- a/examples/osgunittests/MultiThreadRead.cpp +++ b/examples/osgunittests/MultiThreadRead.cpp @@ -18,7 +18,10 @@ #include #include +#include + #include +#include struct OSG_EXPORT RefBarrier : public osg::Referenced, public OpenThreads::Barrier { @@ -104,12 +107,76 @@ public: osg::ref_ptr _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 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 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 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 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 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 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"<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 startBarrier = new RefBarrier(numThreads+1); osg::ref_ptr endBarrier = new RefBarrier(numThreads+1); diff --git a/examples/osgunittests/MultiThreadRead.h b/examples/osgunittests/MultiThreadRead.h index 77b77068d..0f9600c46 100644 --- a/examples/osgunittests/MultiThreadRead.h +++ b/examples/osgunittests/MultiThreadRead.h @@ -21,6 +21,8 @@ #ifndef MULTITHREADEDREAD_H #define MULTITHREADEDREAD_H 1 -extern void runMultiThreadReadTests(int numThreads); +#include + +extern void runMultiThreadReadTests(int numThreads, osg::ArgumentParser& arguments); #endif diff --git a/examples/osgunittests/osgunittests.cpp b/examples/osgunittests/osgunittests.cpp index c22c768c8..746c70807 100644 --- a/examples/osgunittests/osgunittests.cpp +++ b/examples/osgunittests/osgunittests.cpp @@ -628,7 +628,7 @@ int main( int argc, char** argv ) if (numReadThreads>0) { - runMultiThreadReadTests(numReadThreads); + runMultiThreadReadTests(numReadThreads, arguments); return 0; }