diff --git a/include/osgDB/DatabasePager b/include/osgDB/DatabasePager index 379127759..cfb67c68f 100644 --- a/include/osgDB/DatabasePager +++ b/include/osgDB/DatabasePager @@ -138,6 +138,9 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl ThreadPriority getThreadPriorityOutwithFrame() const { return _threadPriorityOutwithFrame; } + /** Get the number of frames that are currently active.*/ + int getNumFramesActive() const { return _numFramesActive; } + /** Signal the database thread that the update, cull and draw has begun for a new frame. * Note, this is called by the application so that the database pager can go to sleep while the CPU is busy on the main rendering threads. */ void signalBeginFrame(const osg::FrameStamp* framestamp); @@ -261,6 +264,13 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl _databasePagerThreadBlock->set( (!_fileRequestList.empty() || !_childrenToDeleteList.empty()) && !_databasePagerThreadPaused); } + + inline void updateFrameBlock(int delta) + { + OpenThreads::ScopedLock lock(_numFramesActiveMutex); + _numFramesActive += delta; + _frameBlock->set(_numFramesActive==0); + } /** Iterate through the active PagedLOD nodes children removing @@ -277,6 +287,8 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl bool _databasePagerThreadPaused; bool _useFrameBlock; + int _numFramesActive; + mutable OpenThreads::Mutex _numFramesActiveMutex; osg::ref_ptr _frameBlock; int _frameNumber; diff --git a/src/osgDB/DatabasePager.cpp b/src/osgDB/DatabasePager.cpp index 6a5a4f805..cc82ba238 100644 --- a/src/osgDB/DatabasePager.cpp +++ b/src/osgDB/DatabasePager.cpp @@ -28,6 +28,7 @@ DatabasePager::DatabasePager() _databasePagerThreadPaused = false; _useFrameBlock = false; + _numFramesActive = 0; _frameNumber = 0; _frameBlock = new Block; _databasePagerThreadBlock = new Block; @@ -236,20 +237,18 @@ void DatabasePager::signalBeginFrame(const osg::FrameStamp* framestamp) } //else osg::notify(osg::INFO) << "signalBeginFrame >>>>>>>>>>>>>>>>"<reset(); - - if (_threadPriorityDuringFrame!=getSchedulePriority()) + if (_numFramesActive>0 && _threadPriorityDuringFrame!=getSchedulePriority()) setSchedulePriority(_threadPriorityDuringFrame); - } void DatabasePager::signalEndFrame() { //osg::notify(osg::INFO) << "signalEndFrame <<<<<<<<<<<<<<<<<<<< "<release(); + updateFrameBlock(-1); - if (_threadPriorityOutwithFrame!=getSchedulePriority()) + if (_numFramesActive<=0 && _threadPriorityOutwithFrame!=getSchedulePriority()) setSchedulePriority(_threadPriorityOutwithFrame); }