Tripped out experiemental threadSafe_ methods in ReaderWriter
This commit is contained in:
parent
5c5ceef90d
commit
ffcd95b004
@ -134,7 +134,7 @@ int main( int argc, char **argv )
|
|||||||
if (obj.valid())
|
if (obj.valid())
|
||||||
{
|
{
|
||||||
std::cout<<" write to archive "<<*itr<<std::endl;
|
std::cout<<" write to archive "<<*itr<<std::endl;
|
||||||
archive->threadSafe_writeObject(*obj, *itr);
|
archive->writeObject(*obj, *itr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -150,7 +150,7 @@ int main( int argc, char **argv )
|
|||||||
++itr)
|
++itr)
|
||||||
{
|
{
|
||||||
osg::Timer_t start = osg::Timer::instance()->tick();
|
osg::Timer_t start = osg::Timer::instance()->tick();
|
||||||
osgDB::ReaderWriter::ReadResult result = archive->threadSafe_readObject(*itr);
|
osgDB::ReaderWriter::ReadResult result = archive->readObject(*itr);
|
||||||
osg::ref_ptr<osg::Object> obj = result.getObject();
|
osg::ref_ptr<osg::Object> obj = result.getObject();
|
||||||
std::cout<<"readObejct time = "<<osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick())<<std::endl;
|
std::cout<<"readObejct time = "<<osg::Timer::instance()->delta_m(start,osg::Timer::instance()->tick())<<std::endl;
|
||||||
if (obj.valid())
|
if (obj.valid())
|
||||||
|
@ -50,8 +50,6 @@ class OSGDB_EXPORT Archive : public ReaderWriter
|
|||||||
/** Get the full list of file names available in the archive.*/
|
/** Get the full list of file names available in the archive.*/
|
||||||
virtual bool getFileNames(FileNameList& fileNameList) const = 0;
|
virtual bool getFileNames(FileNameList& fileNameList) const = 0;
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
virtual ReadResult readObject(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
||||||
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
virtual ReadResult readImage(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
||||||
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
virtual ReadResult readHeightField(const std::string& /*fileName*/,const Options* =NULL) = 0;
|
||||||
|
@ -19,10 +19,7 @@
|
|||||||
#include <osg/Shape>
|
#include <osg/Shape>
|
||||||
#include <osg/Node>
|
#include <osg/Node>
|
||||||
|
|
||||||
#include <OpenThreads/ScopedLock>
|
|
||||||
|
|
||||||
#include <osgDB/Export>
|
#include <osgDB/Export>
|
||||||
#include <osgDB/ReentrantMutex>
|
|
||||||
|
|
||||||
#include <deque>
|
#include <deque>
|
||||||
|
|
||||||
@ -217,38 +214,6 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
|||||||
WRITE,
|
WRITE,
|
||||||
CREATE
|
CREATE
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SERIALIZER() OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
|
|
||||||
virtual ReadResult threadSafe_openArchive(const std::string& fileName,ArchiveStatus status, unsigned int indexBlockSize=4096, const Options* options=NULL) { SERIALIZER(); return openArchive(fileName,status, indexBlockSize, options); }
|
|
||||||
|
|
||||||
/** open an archive for reading.*/
|
|
||||||
virtual ReadResult threadSafe_openArchive(std::istream& fin,const Options* options=NULL) { SERIALIZER(); return openArchive(fin, options); }
|
|
||||||
|
|
||||||
virtual ReadResult threadSafe_readObject(const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return readObject(fileName,options); }
|
|
||||||
virtual ReadResult threadSafe_readImage(const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return readImage(fileName,options); }
|
|
||||||
virtual ReadResult threadSafe_readHeightField(const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return readHeightField(fileName,options); }
|
|
||||||
virtual ReadResult threadSafe_readNode(const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return readNode(fileName,options); }
|
|
||||||
|
|
||||||
virtual WriteResult threadSafe_writeObject(const osg::Object& obj,const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return writeObject(obj, fileName,options); }
|
|
||||||
virtual WriteResult threadSafe_writeImage(const osg::Image& image,const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return writeImage(image, fileName,options); }
|
|
||||||
virtual WriteResult threadSafe_writeHeightField(const osg::HeightField& heightField,const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return writeHeightField(heightField, fileName,options); }
|
|
||||||
virtual WriteResult threadSafe_writeNode(const osg::Node& node,const std::string& fileName,const Options* options=NULL) { SERIALIZER(); return writeNode(node, fileName,options); }
|
|
||||||
|
|
||||||
virtual ReadResult threadSafe_readObject(std::istream& fin,const Options* options=NULL) { SERIALIZER(); return readObject(fin,options); }
|
|
||||||
virtual ReadResult threadSafe_readImage(std::istream& fin,const Options* options=NULL) { SERIALIZER(); return readImage(fin,options); }
|
|
||||||
virtual ReadResult threadSafe_readHeightField(std::istream& fin,const Options* options=NULL) { SERIALIZER(); return readHeightField(fin,options); }
|
|
||||||
virtual ReadResult threadSafe_readNode(std::istream& fin,const Options* options=NULL) { SERIALIZER(); return readNode(fin,options); }
|
|
||||||
|
|
||||||
virtual WriteResult threadSafe_writeObject(const osg::Object& obj,std::ostream& fout,const Options* options=NULL) { SERIALIZER(); return writeObject(obj, fout, options); }
|
|
||||||
virtual WriteResult threadSafe_writeImage(const osg::Image& image,std::ostream& fout,const Options* options=NULL) { SERIALIZER(); return writeImage(image, fout, options); }
|
|
||||||
virtual WriteResult threadSafe_writeHeightField(const osg::HeightField& heightField,std::ostream& fout,const Options* options=NULL) { SERIALIZER(); return writeHeightField(heightField, fout, options); }
|
|
||||||
virtual WriteResult threadSafe_writeNode(const osg::Node& node,std::ostream& fout,const Options* options=NULL) { SERIALIZER(); return writeNode(node, fout, options); }
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
|
/** open an archive for reading, writing or or to create an empty archive for writing to.*/
|
||||||
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
virtual ReadResult openArchive(const std::string& /*fileName*/,ArchiveStatus, unsigned int =4096, const Options* =NULL) { return ReadResult(ReadResult::FILE_NOT_HANDLED); }
|
||||||
@ -276,12 +241,6 @@ class OSGDB_EXPORT ReaderWriter : public osg::Object
|
|||||||
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
virtual WriteResult writeHeightField(const osg::HeightField& /*heightField*/,std::ostream& /*fout*/,const Options* =NULL) {return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
||||||
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
virtual WriteResult writeNode(const osg::Node& /*node*/,std::ostream& /*fout*/,const Options* =NULL) { return WriteResult(WriteResult::FILE_NOT_HANDLED); }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
protected:
|
|
||||||
|
|
||||||
osgDB::ReentrantMutex _serializerMutex;
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1120,7 +1120,7 @@ struct Registry::ReadObjectFunctor : public Registry::ReadFunctor
|
|||||||
{
|
{
|
||||||
ReadObjectFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadObjectFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
|
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.threadSafe_readObject(_filename, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readObject(_filename, _options); }
|
||||||
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validObject(); }
|
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validObject(); }
|
||||||
virtual bool isValid(osg::Object* object) const { return object!=0; }
|
virtual bool isValid(osg::Object* object) const { return object!=0; }
|
||||||
};
|
};
|
||||||
@ -1129,7 +1129,7 @@ struct Registry::ReadImageFunctor : public Registry::ReadFunctor
|
|||||||
{
|
{
|
||||||
ReadImageFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadImageFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
|
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.threadSafe_readImage(_filename, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw)const { return rw.readImage(_filename, _options); }
|
||||||
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validImage(); }
|
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validImage(); }
|
||||||
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Image*>(object)!=0; }
|
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Image*>(object)!=0; }
|
||||||
};
|
};
|
||||||
@ -1138,7 +1138,7 @@ struct Registry::ReadHeightFieldFunctor : public Registry::ReadFunctor
|
|||||||
{
|
{
|
||||||
ReadHeightFieldFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadHeightFieldFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
|
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.threadSafe_readHeightField(_filename, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readHeightField(_filename, _options); }
|
||||||
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validHeightField(); }
|
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validHeightField(); }
|
||||||
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::HeightField*>(object)!=0; }
|
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::HeightField*>(object)!=0; }
|
||||||
};
|
};
|
||||||
@ -1147,7 +1147,7 @@ struct Registry::ReadNodeFunctor : public Registry::ReadFunctor
|
|||||||
{
|
{
|
||||||
ReadNodeFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadNodeFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
|
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.threadSafe_readNode(_filename, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.readNode(_filename, _options); }
|
||||||
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validNode(); }
|
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validNode(); }
|
||||||
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Node*>(object)!=0; }
|
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osg::Node*>(object)!=0; }
|
||||||
|
|
||||||
@ -1163,7 +1163,7 @@ struct Registry::ReadArchiveFunctor : public Registry::ReadFunctor
|
|||||||
ReaderWriter::ArchiveStatus _status;
|
ReaderWriter::ArchiveStatus _status;
|
||||||
unsigned int _indexBlockSizeHint;
|
unsigned int _indexBlockSizeHint;
|
||||||
|
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.threadSafe_openArchive(_filename, _status, _indexBlockSizeHint, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw) const { return rw.openArchive(_filename, _status, _indexBlockSizeHint, _options); }
|
||||||
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validArchive(); }
|
virtual bool isValid(ReaderWriter::ReadResult& readResult) const { return readResult.validArchive(); }
|
||||||
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osgDB::Archive*>(object)!=0; }
|
virtual bool isValid(osg::Object* object) const { return dynamic_cast<osgDB::Archive*>(object)!=0; }
|
||||||
|
|
||||||
@ -1192,7 +1192,7 @@ ReaderWriter::ReadResult Registry::read(const ReadFunctor& readFunctor)
|
|||||||
osg::ref_ptr<ReaderWriter::Options> options = new ReaderWriter::Options;
|
osg::ref_ptr<ReaderWriter::Options> options = new ReaderWriter::Options;
|
||||||
options->setDatabasePath(archiveName);
|
options->setDatabasePath(archiveName);
|
||||||
|
|
||||||
return archive->threadSafe_readObject(fileName,options.get());
|
return archive->readObject(fileName,options.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if filename contains archive
|
// if filename contains archive
|
||||||
@ -1387,7 +1387,7 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,
|
|||||||
AvailableReaderWriterIterator itr(_rwList);
|
AvailableReaderWriterIterator itr(_rwList);
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeObject(obj,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeObject(obj,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1398,7 +1398,7 @@ ReaderWriter::WriteResult Registry::writeObjectImplementation(const Object& obj,
|
|||||||
{
|
{
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeObject(obj,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeObject(obj,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1430,7 +1430,7 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
|
|||||||
AvailableReaderWriterIterator itr(_rwList);
|
AvailableReaderWriterIterator itr(_rwList);
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeImage(image,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeImage(image,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1441,7 +1441,7 @@ ReaderWriter::WriteResult Registry::writeImageImplementation(const Image& image,
|
|||||||
{
|
{
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeImage(image,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeImage(image,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1472,7 +1472,7 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
|
|||||||
AvailableReaderWriterIterator itr(_rwList);
|
AvailableReaderWriterIterator itr(_rwList);
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeHeightField(HeightField,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeHeightField(HeightField,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1483,7 +1483,7 @@ ReaderWriter::WriteResult Registry::writeHeightFieldImplementation(const HeightF
|
|||||||
{
|
{
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeHeightField(HeightField,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeHeightField(HeightField,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1514,7 +1514,7 @@ ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,con
|
|||||||
AvailableReaderWriterIterator itr(_rwList);
|
AvailableReaderWriterIterator itr(_rwList);
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeNode(node,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeNode(node,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
@ -1525,7 +1525,7 @@ ReaderWriter::WriteResult Registry::writeNodeImplementation(const Node& node,con
|
|||||||
{
|
{
|
||||||
for(;itr.valid();++itr)
|
for(;itr.valid();++itr)
|
||||||
{
|
{
|
||||||
ReaderWriter::WriteResult rr = itr->threadSafe_writeNode(node,fileName,_options.get());
|
ReaderWriter::WriteResult rr = itr->writeNode(node,fileName,_options.get());
|
||||||
if (rr.success()) return rr;
|
if (rr.success()) return rr;
|
||||||
else results.push_back(rr);
|
else results.push_back(rr);
|
||||||
}
|
}
|
||||||
|
@ -122,11 +122,11 @@ class NetReader : public osgDB::ReaderWriter
|
|||||||
{
|
{
|
||||||
switch(objectType)
|
switch(objectType)
|
||||||
{
|
{
|
||||||
case(OBJECT): return rw->threadSafe_readObject(fin,options);
|
case(OBJECT): return rw->readObject(fin,options);
|
||||||
case(ARCHIVE): return rw->threadSafe_openArchive(fin,options);
|
case(ARCHIVE): return rw->openArchive(fin,options);
|
||||||
case(IMAGE): return rw->threadSafe_readImage(fin,options);
|
case(IMAGE): return rw->readImage(fin,options);
|
||||||
case(HEIGHTFIELD): return rw->threadSafe_readHeightField(fin,options);
|
case(HEIGHTFIELD): return rw->readHeightField(fin,options);
|
||||||
case(NODE): return rw->threadSafe_readNode(fin,options);
|
case(NODE): return rw->readNode(fin,options);
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
return ReadResult::FILE_NOT_HANDLED;
|
return ReadResult::FILE_NOT_HANDLED;
|
||||||
|
@ -230,6 +230,8 @@ OSGA_Archive::~OSGA_Archive()
|
|||||||
|
|
||||||
bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSize)
|
bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsigned int indexBlockSize)
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
if (status==READ)
|
if (status==READ)
|
||||||
{
|
{
|
||||||
_status = status;
|
_status = status;
|
||||||
@ -289,9 +291,11 @@ bool OSGA_Archive::open(const std::string& filename, ArchiveStatus status, unsig
|
|||||||
|
|
||||||
bool OSGA_Archive::open(std::istream& fin)
|
bool OSGA_Archive::open(std::istream& fin)
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
osg::notify(osg::NOTICE)<<"OSGA_Archive::open"<<std::endl;
|
osg::notify(osg::NOTICE)<<"OSGA_Archive::open"<<std::endl;
|
||||||
static_cast<std::istream&>(_output).rdbuf(fin.rdbuf());
|
static_cast<std::istream&>(_input).rdbuf(fin.rdbuf());
|
||||||
return false;
|
return _open(_input);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool OSGA_Archive::_open(std::istream& input)
|
bool OSGA_Archive::_open(std::istream& input)
|
||||||
@ -359,6 +363,8 @@ bool OSGA_Archive::_open(std::istream& input)
|
|||||||
|
|
||||||
void OSGA_Archive::close()
|
void OSGA_Archive::close()
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
_input.close();
|
_input.close();
|
||||||
|
|
||||||
if (_status==WRITE)
|
if (_status==WRITE)
|
||||||
@ -375,6 +381,8 @@ std::string OSGA_Archive::getMasterFileName() const
|
|||||||
|
|
||||||
bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const
|
bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
fileNameList.clear();
|
fileNameList.clear();
|
||||||
fileNameList.reserve(_indexMap.size());
|
fileNameList.reserve(_indexMap.size());
|
||||||
for(FileNamePositionMap::const_iterator itr=_indexMap.begin();
|
for(FileNamePositionMap::const_iterator itr=_indexMap.begin();
|
||||||
@ -389,6 +397,8 @@ bool OSGA_Archive::getFileNames(FileNameList& fileNameList) const
|
|||||||
|
|
||||||
void OSGA_Archive::writeIndexBlocks()
|
void OSGA_Archive::writeIndexBlocks()
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
if (_status==WRITE)
|
if (_status==WRITE)
|
||||||
{
|
{
|
||||||
for(IndexBlockList::iterator itr=_indexBlockList.begin();
|
for(IndexBlockList::iterator itr=_indexBlockList.begin();
|
||||||
@ -410,6 +420,8 @@ bool OSGA_Archive::fileExists(const std::string& filename) const
|
|||||||
|
|
||||||
bool OSGA_Archive::addFileReference(pos_type position, size_type size, const std::string& fileName)
|
bool OSGA_Archive::addFileReference(pos_type position, size_type size, const std::string& fileName)
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
if (_status==READ)
|
if (_status==READ)
|
||||||
{
|
{
|
||||||
osg::notify(osg::INFO)<<"OSGA_Archive::getPositionForNewEntry("<<fileName<<") failed, archive opened as read only."<<std::endl;
|
osg::notify(osg::INFO)<<"OSGA_Archive::getPositionForNewEntry("<<fileName<<") failed, archive opened as read only."<<std::endl;
|
||||||
@ -507,29 +519,31 @@ class proxy_streambuf : public std::streambuf
|
|||||||
struct OSGA_Archive::ReadObjectFunctor : public OSGA_Archive::ReadFunctor
|
struct OSGA_Archive::ReadObjectFunctor : public OSGA_Archive::ReadFunctor
|
||||||
{
|
{
|
||||||
ReadObjectFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadObjectFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.threadSafe_readObject(input, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readObject(input, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::ReadImageFunctor : public OSGA_Archive::ReadFunctor
|
struct OSGA_Archive::ReadImageFunctor : public OSGA_Archive::ReadFunctor
|
||||||
{
|
{
|
||||||
ReadImageFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadImageFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input)const { return rw.threadSafe_readImage(input, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input)const { return rw.readImage(input, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::ReadHeightFieldFunctor : public OSGA_Archive::ReadFunctor
|
struct OSGA_Archive::ReadHeightFieldFunctor : public OSGA_Archive::ReadFunctor
|
||||||
{
|
{
|
||||||
ReadHeightFieldFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadHeightFieldFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.threadSafe_readHeightField(input, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readHeightField(input, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::ReadNodeFunctor : public OSGA_Archive::ReadFunctor
|
struct OSGA_Archive::ReadNodeFunctor : public OSGA_Archive::ReadFunctor
|
||||||
{
|
{
|
||||||
ReadNodeFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
ReadNodeFunctor(const std::string& filename, const ReaderWriter::Options* options):ReadFunctor(filename,options) {}
|
||||||
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.threadSafe_readNode(input, _options); }
|
virtual ReaderWriter::ReadResult doRead(ReaderWriter& rw, std::istream& input) const { return rw.readNode(input, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ReaderWriter::ReadResult OSGA_Archive::read(const ReadFunctor& readFunctor)
|
ReaderWriter::ReadResult OSGA_Archive::read(const ReadFunctor& readFunctor)
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
if (_status!=READ)
|
if (_status!=READ)
|
||||||
{
|
{
|
||||||
osg::notify(osg::INFO)<<"OSGA_Archive::readObject(obj, "<<readFunctor._filename<<") failed, archive opened as read only."<<std::endl;
|
osg::notify(osg::INFO)<<"OSGA_Archive::readObject(obj, "<<readFunctor._filename<<") failed, archive opened as read only."<<std::endl;
|
||||||
@ -594,7 +608,7 @@ struct OSGA_Archive::WriteObjectFunctor : public OSGA_Archive::WriteFunctor
|
|||||||
_object(object) {}
|
_object(object) {}
|
||||||
const osg::Object& _object;
|
const osg::Object& _object;
|
||||||
|
|
||||||
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.threadSafe_writeObject(_object, output, _options); }
|
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeObject(_object, output, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor
|
struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor
|
||||||
@ -604,7 +618,7 @@ struct OSGA_Archive::WriteImageFunctor : public OSGA_Archive::WriteFunctor
|
|||||||
_object(object) {}
|
_object(object) {}
|
||||||
const osg::Image& _object;
|
const osg::Image& _object;
|
||||||
|
|
||||||
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output)const { return rw.threadSafe_writeImage(_object, output, _options); }
|
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output)const { return rw.writeImage(_object, output, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor
|
struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor
|
||||||
@ -614,7 +628,7 @@ struct OSGA_Archive::WriteHeightFieldFunctor : public OSGA_Archive::WriteFunctor
|
|||||||
_object(object) {}
|
_object(object) {}
|
||||||
const osg::HeightField& _object;
|
const osg::HeightField& _object;
|
||||||
|
|
||||||
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.threadSafe_writeHeightField(_object, output, _options); }
|
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeHeightField(_object, output, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct OSGA_Archive::WriteNodeFunctor : public OSGA_Archive::WriteFunctor
|
struct OSGA_Archive::WriteNodeFunctor : public OSGA_Archive::WriteFunctor
|
||||||
@ -624,11 +638,13 @@ struct OSGA_Archive::WriteNodeFunctor : public OSGA_Archive::WriteFunctor
|
|||||||
_object(object) {}
|
_object(object) {}
|
||||||
const osg::Node& _object;
|
const osg::Node& _object;
|
||||||
|
|
||||||
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.threadSafe_writeNode(_object, output, _options); }
|
virtual ReaderWriter::WriteResult doWrite(ReaderWriter& rw, std::ostream& output) const { return rw.writeNode(_object, output, _options); }
|
||||||
};
|
};
|
||||||
|
|
||||||
ReaderWriter::WriteResult OSGA_Archive::write(const WriteFunctor& writeFunctor)
|
ReaderWriter::WriteResult OSGA_Archive::write(const WriteFunctor& writeFunctor)
|
||||||
{
|
{
|
||||||
|
SERIALIZER();
|
||||||
|
|
||||||
if (_status!=WRITE)
|
if (_status!=WRITE)
|
||||||
{
|
{
|
||||||
osg::notify(osg::INFO)<<"OSGA_Archive::write(obj, "<<writeFunctor._filename<<") failed, archive opened as read only."<<std::endl;
|
osg::notify(osg::INFO)<<"OSGA_Archive::write(obj, "<<writeFunctor._filename<<") failed, archive opened as read only."<<std::endl;
|
||||||
|
@ -15,6 +15,11 @@
|
|||||||
#include <osgDB/Archive>
|
#include <osgDB/Archive>
|
||||||
#include <osgDB/FileNameUtils>
|
#include <osgDB/FileNameUtils>
|
||||||
|
|
||||||
|
#include <OpenThreads/ScopedLock>
|
||||||
|
#include <osgDB/ReentrantMutex>
|
||||||
|
|
||||||
|
#define SERIALIZER() OpenThreads::ScopedLock<osgDB::ReentrantMutex> lock(_serializerMutex)
|
||||||
|
|
||||||
class OSGA_Archive : public osgDB::Archive
|
class OSGA_Archive : public osgDB::Archive
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -78,6 +83,8 @@ class OSGA_Archive : public osgDB::Archive
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
|
mutable osgDB::ReentrantMutex _serializerMutex;
|
||||||
|
|
||||||
#if defined(_MSC_VER)
|
#if defined(_MSC_VER)
|
||||||
typedef __int64 pos_type;
|
typedef __int64 pos_type;
|
||||||
typedef __int64 size_type;
|
typedef __int64 size_type;
|
||||||
|
@ -61,7 +61,7 @@ public:
|
|||||||
osg::ref_ptr<ReaderWriter::Options> local_options = new ReaderWriter::Options;
|
osg::ref_ptr<ReaderWriter::Options> local_options = new ReaderWriter::Options;
|
||||||
local_options->setDatabasePath(file);
|
local_options->setDatabasePath(file);
|
||||||
|
|
||||||
ReadResult result_2 = result.getArchive()->threadSafe_readImage(result.getArchive()->getMasterFileName(),local_options.get());
|
ReadResult result_2 = result.getArchive()->readImage(result.getArchive()->getMasterFileName(),local_options.get());
|
||||||
|
|
||||||
|
|
||||||
// register the archive so that it is cached for future use.
|
// register the archive so that it is cached for future use.
|
||||||
@ -81,7 +81,7 @@ public:
|
|||||||
osg::ref_ptr<ReaderWriter::Options> local_options = new ReaderWriter::Options;
|
osg::ref_ptr<ReaderWriter::Options> local_options = new ReaderWriter::Options;
|
||||||
local_options->setDatabasePath(file);
|
local_options->setDatabasePath(file);
|
||||||
|
|
||||||
ReadResult result_2 = result.getArchive()->threadSafe_readNode(result.getArchive()->getMasterFileName(),local_options.get());
|
ReadResult result_2 = result.getArchive()->readNode(result.getArchive()->getMasterFileName(),local_options.get());
|
||||||
|
|
||||||
|
|
||||||
// register the archive so that it is cached for future use.
|
// register the archive so that it is cached for future use.
|
||||||
|
@ -3724,13 +3724,13 @@ void DataSet::_equalizeRow(Row& row)
|
|||||||
|
|
||||||
void DataSet::_writeNodeFile(const osg::Node& node,const std::string& filename)
|
void DataSet::_writeNodeFile(const osg::Node& node,const std::string& filename)
|
||||||
{
|
{
|
||||||
if (_archive.valid()) _archive->threadSafe_writeNode(node,filename);
|
if (_archive.valid()) _archive->writeNode(node,filename);
|
||||||
else osgDB::writeNodeFile(node, filename);
|
else osgDB::writeNodeFile(node, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
void DataSet::_writeImageFile(const osg::Image& image,const std::string& filename)
|
void DataSet::_writeImageFile(const osg::Image& image,const std::string& filename)
|
||||||
{
|
{
|
||||||
if (_archive.valid()) _archive->threadSafe_writeImage(image,filename);
|
if (_archive.valid()) _archive->writeImage(image,filename);
|
||||||
else osgDB::writeImageFile(image, filename);
|
else osgDB::writeImageFile(image, filename);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user