Added first step to adding pruning of expired image requests.

This commit is contained in:
Robert Osfield 2012-11-13 11:45:20 +00:00
parent ad1cec1b2e
commit e72af02c2b
3 changed files with 41 additions and 18 deletions

View File

@ -21,6 +21,7 @@
#include <osg/FrameStamp> #include <osg/FrameStamp>
#include <OpenThreads/Mutex> #include <OpenThreads/Mutex>
#include <OpenThreads/Atomic>
#include <osgDB/ReaderWriter> #include <osgDB/ReaderWriter>
#include <osgDB/Options> #include <osgDB/Options>
@ -87,6 +88,14 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
/** Merge the changes to the scene graph. */ /** Merge the changes to the scene graph. */
virtual void updateSceneGraph(const osg::FrameStamp &frameStamp); virtual void updateSceneGraph(const osg::FrameStamp &frameStamp);
/** Signal the image thread that the update, cull and draw has begun for a new frame.
* Note, this is called by the application so that the image pager can go to sleep while the CPU is busy on the main rendering threads. */
virtual void signalBeginFrame(const osg::FrameStamp* framestamp);
/** Signal the image thread that the update, cull and draw dispatch has completed.
* Note, this is called by the application so that the image pager can go to wake back up now the main rendering threads are iddle waiting for the next frame.*/
virtual void signalEndFrame();
int cancel(); int cancel();
protected: protected:
@ -105,6 +114,7 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
_timeToMergeBy(0.0), _timeToMergeBy(0.0),
_attachmentIndex(-1) {} _attachmentIndex(-1) {}
unsigned int _frameNumber;
double _timeToMergeBy; double _timeToMergeBy;
std::string _fileName; std::string _fileName;
osg::ref_ptr<Options> _loadOptions; osg::ref_ptr<Options> _loadOptions;
@ -160,6 +170,9 @@ class OSGDB_EXPORT ImagePager : public osg::NodeVisitor::ImageRequestHandler
bool _done; bool _done;
bool _databasePagerThreadPaused; bool _databasePagerThreadPaused;
OpenThreads::Atomic _frameNumber;
OpenThreads::Mutex _ir_mutex;
osg::ref_ptr<ReadQueue> _readQueue; osg::ref_ptr<ReadQueue> _readQueue;
typedef std::vector< osg::ref_ptr<ImageThread> > ImageThreads; typedef std::vector< osg::ref_ptr<ImageThread> > ImageThreads;

View File

@ -78,19 +78,14 @@ void ImagePager::ReadQueue::clear()
updateBlock(); updateBlock();
} }
void ImagePager::ReadQueue::add(ImagePager::ImageRequest* databaseRequest) void ImagePager::ReadQueue::add(ImagePager::ImageRequest* imageRequest)
{ {
// tempo hack to avoid the ImagePager accumulating requests when it can keep up,
// note this will mean that only one ImageSequence can be properly managed at one time,
// this hack will be removed once a better system for managing expiry of requests is introduced.
// clear();
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_requestMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_requestMutex);
_requestList.push_back(databaseRequest); _requestList.push_back(imageRequest);
databaseRequest->_requestQueue = this; imageRequest->_requestQueue = this;
OSG_INFO<<"ImagePager::ReadQueue::add("<<databaseRequest->_fileName<<"), size()="<<_requestList.size()<<std::endl; OSG_INFO<<"ImagePager::ReadQueue::add("<<imageRequest->_fileName<<"), size()="<<_requestList.size()<<std::endl;
updateBlock(); updateBlock();
} }
@ -177,6 +172,21 @@ int ImagePager::ImageThread::cancel()
return result; return result;
} }
void ImagePager::signalBeginFrame(const osg::FrameStamp* framestamp)
{
if (framestamp)
{
//OSG_INFO << "signalBeginFrame "<<framestamp->getFrameNumber()<<">>>>>>>>>>>>>>>>"<<std::endl;
_frameNumber.exchange(framestamp->getFrameNumber());
} //else OSG_INFO << "signalBeginFrame >>>>>>>>>>>>>>>>"<<std::endl;
}
void ImagePager::signalEndFrame()
{
}
void ImagePager::ImageThread::run() void ImagePager::ImageThread::run()
{ {
OSG_INFO<<"ImagePager::ImageThread::run() "<<this<<std::endl; OSG_INFO<<"ImagePager::ImageThread::run() "<<this<<std::endl;
@ -269,9 +279,9 @@ ImagePager::ImagePager():
_readQueue = new ReadQueue(this,"Image Queue"); _readQueue = new ReadQueue(this,"Image Queue");
_completedQueue = new RequestQueue; _completedQueue = new RequestQueue;
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 1")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 1"));
#if 1
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 2")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 2"));
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 3")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 3"));
#if 0
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 4")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 4"));
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 5")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 5"));
_imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 6")); _imageThreads.push_back(new ImageThread(this, ImageThread::HANDLE_ALL_REQUESTS, "Image Thread 6"));

View File

@ -759,10 +759,10 @@ void ViewerBase::renderingTraversals()
{ {
Scene* scene = *sitr; Scene* scene = *sitr;
osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0; osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0;
if (dp) if (dp) dp->signalBeginFrame(frameStamp);
{
dp->signalBeginFrame(frameStamp); osgDB::ImagePager* ip = scene ? scene->getImagePager() : 0;
} if (ip) ip->signalBeginFrame(frameStamp);
if (scene->getSceneData()) if (scene->getSceneData())
{ {
@ -841,10 +841,10 @@ void ViewerBase::renderingTraversals()
{ {
Scene* scene = *sitr; Scene* scene = *sitr;
osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0; osgDB::DatabasePager* dp = scene ? scene->getDatabasePager() : 0;
if (dp) if (dp) dp->signalEndFrame();
{
dp->signalEndFrame(); osgDB::ImagePager* ip = scene ? scene->getImagePager() : 0;
} if (ip) ip->signalEndFrame();
} }
// wait till the dynamic draw is complete. // wait till the dynamic draw is complete.