From 56044e6cf7d1ee74920b00a9cd562bcb9efff934 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 20 Aug 2003 07:36:47 +0000 Subject: [PATCH] Moved the delete of expired subgraphs to the database thread to improve the stability of the frame rate. --- src/osgPlugins/txp/trPagePageManager.cpp | 45 +++++------------------- src/osgPlugins/txp/trPagePageManager.h | 18 ++-------- 2 files changed, 10 insertions(+), 53 deletions(-) diff --git a/src/osgPlugins/txp/trPagePageManager.cpp b/src/osgPlugins/txp/trPagePageManager.cpp index 715395044..5f1568616 100644 --- a/src/osgPlugins/txp/trPagePageManager.cpp +++ b/src/osgPlugins/txp/trPagePageManager.cpp @@ -167,22 +167,11 @@ void OSGPageManager::LoadOneTile(trpgManagedTile* tile) tileGroup = archive->LoadTile(NULL,pageManage,tile,&parentNode); if (tileGroup) { -#ifdef USE_THREADLOOP_DELETE - // Make an extra reference to it because we want it back for deletion - // RO, commenting out as we don't want to do delete here, we want it to happen in the merge thread. - tileGroup->ref(); -#endif - // we only put tiles with NULL parent to merge list - // others are referenced when added as a child osgGuard g(changeListMutex); -// if(parentNode) -// parentNode->addChild(tileGroup) ; -// else if(parentNode) toMerge.push_back(MergePair(parentNode,tileGroup)) ; else toMerge.push_back(MergePair(0,tileGroup)) ; - //toMergeParent.push_back(parentNode ); } else { @@ -206,7 +195,7 @@ bool OSGPageManager::ThreadLoop(PagingThread* t) //std::cout<<"OSGPageManager::ThreadLoop()"< unhook; - std::vector nextDelete; + std::vector < osg::ref_ptr > nextDelete; //bool pagingActive = false; do @@ -251,7 +240,8 @@ bool OSGPageManager::ThreadLoop(PagingThread* t) pageManage->AckUnload(); } - nextDelete.clear(); + //nextDelete.clear(); + { osgGuard g(changeListMutex); // Add to the unhook list @@ -260,25 +250,13 @@ bool OSGPageManager::ThreadLoop(PagingThread* t) toUnhook.push_back(unhook[kk]); } // Also get the list of deletions while we're here -#ifdef USE_THREADLOOP_DELETE // use the stl Luke :-) swap is constant time operation that do a = b; b.clear() // if a is empty which is our case nextDelete.swap(toDelete); - // toDelete.clear(); -#endif } -#ifdef USE_THREADLOOP_DELETE - // Unreference whatever we're supposed to delete - for (unsigned int gi=0;giunref(); - } - } -#endif + // unref the delete list. + nextDelete.clear(); // Now do a single load @@ -336,7 +314,7 @@ void OSGPageManager::UpdatePositionThread(double inLocX,double inLocY) bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) { std::vector mergeList; - std::vector unhookList; + std::vector > unhookList; // Make local copies of the merge and unhook lists { @@ -345,9 +323,6 @@ bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) // if a is empty which is our case mergeList.swap(toMerge); unhookList.swap(toUnhook); -// toMerge.clear(); -// toMergeParent.clear(); -// toUnhook.clear(); } // visitor to go through unhooked subgraphs to release texture objects @@ -357,7 +332,7 @@ bool OSGPageManager::MergeUpdateThread(osg::Group *rootNode) // Do the unhooking first for (unsigned int ui=0;uiaddChild(mergeMe); else diff --git a/src/osgPlugins/txp/trPagePageManager.h b/src/osgPlugins/txp/trPagePageManager.h index 50973c286..b32824e04 100644 --- a/src/osgPlugins/txp/trPagePageManager.h +++ b/src/osgPlugins/txp/trPagePageManager.h @@ -34,15 +34,6 @@ #include -// Dec 2002, Robert Osfield -> comment out now, as we actually do want to delete in the main thread -// as the deletion of the display and texture object isn't thread safe. -// Jan 2002, Robert osfield -> comment back in now, as I've changed the way the -// glDelete part is handled so that its much less likely to hit a race condtion, -// in theory its still not thread safe, but a point swap should be much faster -// and less likely to encounter a race condition on the static caches of display -// and texture object lists. -// #define USE_THREADLOOP_DELETE - namespace txp { /* Thread Identifier @@ -156,15 +147,10 @@ namespace txp // Merge list is filled in by the paging thread. typedef std::pair< osg::ref_ptr , osg::ref_ptr > MergePair; std::vector< MergePair > toMerge; - // no need for that - // std::vector toMergeParent; - // Unhook list is filled in by the paging thread - std::vector toUnhook; + std::vector< osg::ref_ptr > toUnhook; -#ifdef USE_THREADLOOP_DELETE // Main thread moves groups to the delete list as soon as they are unhooked - std::vector toDelete; -#endif + std::vector< osg::ref_ptr > toDelete; }; };