From 2236c0576e8da92d86f2085cd1d7d14a30f5e4e7 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 6 Feb 2007 16:23:19 +0000 Subject: [PATCH] Re-enabled processor affinity --- src/osgViewer/Viewer.cpp | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/src/osgViewer/Viewer.cpp b/src/osgViewer/Viewer.cpp index 36f8fcb8d..69a4c9ddd 100644 --- a/src/osgViewer/Viewer.cpp +++ b/src/osgViewer/Viewer.cpp @@ -987,7 +987,7 @@ void Viewer::startThreading() int numProcessors = OpenThreads::GetNumberOfProcessors(); - bool affinity = false;//true; + bool affinity = true; Contexts::iterator citr; @@ -1044,6 +1044,9 @@ void Viewer::startThreading() osg::ref_ptr swapOp = new osg::SwapBuffersOperation(); + typedef std::map ThreadAffinityMap; + ThreadAffinityMap threadAffinityMap; + unsigned int processNum = 1; for(citr = contexts.begin(); citr != contexts.end(); @@ -1058,6 +1061,8 @@ void Viewer::startThreading() #if 1 if (affinity) gc->getGraphicsThread()->setProcessorAffinity(processNum % numProcessors); + + threadAffinityMap[gc->getGraphicsThread()] = processNum % numProcessors; #else if (affinity) gc->getGraphicsThread()->setProcessorAffinity(1); #endif @@ -1106,6 +1111,7 @@ void Viewer::startThreading() #if 1 if (affinity) camera->getCameraThread()->setProcessorAffinity(processNum % numProcessors); + threadAffinityMap[camera->getCameraThread()] = processNum % numProcessors; #else if (affinity) camera->getCameraThread()->setProcessorAffinity(1); #endif @@ -1137,7 +1143,7 @@ void Viewer::startThreading() for(camItr = cameras.begin(); camItr != cameras.end(); - ++camItr, ++processNum) + ++camItr) { osg::Camera* camera = *camItr; if (camera->getCameraThread() && !camera->getCameraThread()->isRunning()) @@ -1150,6 +1156,22 @@ void Viewer::startThreading() if (affinity) OpenThreads::SetProcessorAffinityOfCurrentThread(0); + +#if 0 + if (affinity) + { + for(ThreadAffinityMap::iterator titr = threadAffinityMap.begin(); + titr != threadAffinityMap.end(); + ++titr) + { + titr->first->setProcessorAffinity(titr->second); + } + } + + if (affinity) OpenThreads::SetProcessorAffinityOfCurrentThread(0); +#endif + + for(citr = contexts.begin(); citr != contexts.end(); ++citr)