Refactored the sort of the requestQueue so that there is single code path for doing the sort.

This commit is contained in:
Robert Osfield 2008-06-27 18:59:27 +00:00
parent 214491dd94
commit a9b05e0815
2 changed files with 31 additions and 16 deletions

View File

@ -348,6 +348,8 @@ class OSGDB_EXPORT DatabasePager : public osg::NodeVisitor::DatabaseRequestHandl
struct RequestQueue : public osg::Referenced struct RequestQueue : public osg::Referenced
{ {
typedef std::list< osg::ref_ptr<DatabaseRequest> > RequestList; typedef std::list< osg::ref_ptr<DatabaseRequest> > RequestList;
void sort();
RequestList _requestList; RequestList _requestList;
OpenThreads::Mutex _requestMutex; OpenThreads::Mutex _requestMutex;

View File

@ -83,20 +83,6 @@ RefPtrAdapter<FuncObj> refPtrAdapt(const FuncObj& func)
} }
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// SortFileRequestFunctor
//
struct DatabasePager::SortFileRequestFunctor
{
bool operator() (const osg::ref_ptr<DatabasePager::DatabaseRequest>& lhs,const osg::ref_ptr<DatabasePager::DatabaseRequest>& rhs) const
{
if (lhs->_timestampLastRequest>rhs->_timestampLastRequest) return true;
else if (lhs->_timestampLastRequest<rhs->_timestampLastRequest) return false;
else return (lhs->_priorityLastRequest>rhs->_priorityLastRequest);
}
};
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// FindCompileableGLObjectsVisitor // FindCompileableGLObjectsVisitor
@ -236,6 +222,31 @@ public:
}; };
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// SortFileRequestFunctor
//
struct DatabasePager::SortFileRequestFunctor
{
bool operator() (const osg::ref_ptr<DatabasePager::DatabaseRequest>& lhs,const osg::ref_ptr<DatabasePager::DatabaseRequest>& rhs) const
{
if (lhs->_timestampLastRequest>rhs->_timestampLastRequest) return true;
else if (lhs->_timestampLastRequest<rhs->_timestampLastRequest) return false;
else return (lhs->_priorityLastRequest>rhs->_priorityLastRequest);
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// ReadQueue
//
void DatabasePager::RequestQueue::sort()
{
_requestList.sort(SortFileRequestFunctor());
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //
// ReadQueue // ReadQueue
@ -279,7 +290,8 @@ void DatabasePager::ReadQueue::takeFirst(osg::ref_ptr<DatabaseRequest>& database
if (!_requestList.empty()) if (!_requestList.empty())
{ {
_requestList.sort(SortFileRequestFunctor()); sort();
databaseRequest = _requestList.front(); databaseRequest = _requestList.front();
databaseRequest->_requestQueue = 0; databaseRequest->_requestQueue = 0;
_requestList.erase(_requestList.begin()); _requestList.erase(_requestList.begin());
@ -659,7 +671,8 @@ void DatabasePager::DatabaseThread::run()
if (loadedObjectsNeedToBeCompiled) if (loadedObjectsNeedToBeCompiled)
{ {
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_pager->_dataToCompileList->_requestMutex); OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_pager->_dataToCompileList->_requestMutex);
_pager->_dataToCompileList->_requestList.sort(SortFileRequestFunctor());
_pager->_dataToCompileList->sort();
// Prune all the old entries. // Prune all the old entries.
RequestQueue::RequestList::iterator tooOld RequestQueue::RequestList::iterator tooOld