diff --git a/examples/osgterrain/osgterrain.cpp b/examples/osgterrain/osgterrain.cpp index 126839b2a..ca1db5935 100644 --- a/examples/osgterrain/osgterrain.cpp +++ b/examples/osgterrain/osgterrain.cpp @@ -244,6 +244,9 @@ int main(int argc, char** argv) osgDB::Registry::instance()->setReadFileCallback(new CleanTechniqueReadFileCallback()); } + bool setDatabaseThreadAffinity = false; + unsigned int cpuNum = 0; + while(arguments.read("--db-affinity", cpuNum)) { setDatabaseThreadAffinity = true; } // load the nodes from the commandline arguments. osg::ref_ptr rootnode = osgDB::readNodeFiles(arguments); @@ -294,6 +297,16 @@ int main(int argc, char** argv) // add a viewport to the viewer and attach the scene graph. viewer.setSceneData( rootnode.get() ); + // if required set the DatabaseThread affinity, note must call after viewer.setSceneData() so that the osgViewer::Scene object is constructed with it's DatabasePager. + if (setDatabaseThreadAffinity) + { + for (unsigned int i=0; igetNumDatabaseThreads(); ++i) + { + osgDB::DatabasePager::DatabaseThread* thread = viewer.getDatabasePager()->getDatabaseThread(i); + thread->setProcessorAffinity(cpuNum); + OSG_NOTICE<<"Settings affinity of DatabaseThread="<