Hi Robert,
I work on Linux-platform with pthreads and the 3 parameter sched_setaffinity() 
command will be used. But now this is not anymore interesting, because I have a 
working solution with using both of your suggestions together. Because it is a 
little bit tricky (at least for me) I will present the solution, if anyone else 
needs the same functionality:

1.) We need a new class subclassing DatabasePager. Within this class we need 
following methods:
the constructor
the copy constructor
the descructor
clone()
className()

Here the code (I hope it looks correct, because in preview the [<] makes 
problems!!):

Code:

#include <osgDB/DatabasePager>
class MyDatabasePager : public osgDB::DatabasePager
{
public:

  MyDatabasePager() : osgDB::DatabasePager()
  {
    changeCpuAffinityOfDatabaseThreads();
  }

  MyDatabasePager(const MyDatabasePager& rhs)
  : osgDB::DatabasePager(rhs)
  {
    changeCpuAffinityOfDatabaseThreads();
  }

  virtual const char* className() const
  {
    return "MyDatabasePager";
  }

  virtual MyDatabasePager* clone() const
  {
    return new MyDatabasePager(*this);
  }

protected:

  virtual ~MyDatabasePager() {};

  void changeCpuAffinityOfDatabaseThreads()
  {
    unsigned int cpuNum = 3;
    for (int i=0; i<getNumDatabaseThreads(); ++i)
    {
      getDatabaseThread(i)->setProcessorAffinity(cpuNum);
    }
  }
};



2.) As early as possible you should execute following code:

Code:
osgDB::DatabasePager::prototype() = new MyDatabasePager();



I hope I could help anyone with this code...

Robert: I think the submission would extend the flexibility of OSG, but throw 
it away, if you do not like it, I can now solve my problem without it.

Cheers
Alois


robertosfield wrote:
> Hi WeSee,
> 
> On 20 November 2014 14:57, We See < ()> wrote:Subclassing does not work, 
> because addDatabaseThread() is called from the constructor of DatabasePager 
> and calls therefore DatabasePager::addDatabaseThread() instead my overrided 
> method.
> 
> 
> Interesting problem.  Delaying the call to adding the threads would be one 
> way around this.  This would of course require.
> 
> 
> 
> Calling DatabasePager::setUpThreads(..) manually would be a crude workaround 
> using the present code too.
> 
> 
> 
> >  Using DatabasePager::getDatabaseThread(i) method and set the affinity with 
> > setProcessorAffinity() was also not successful. I don't exactly know why, 
> > but maybe it is because the method must be called before the thread is 
> > started.
> > 
> 
> What platform are you working on?
>  
> 
> >  Could you send me an example, how to change the processor-affinitiy with 
> > your proposals? I have no more ideas, how do get this working, except with 
> > my submission...
> > 
> 
> 
> I have dozens of other submissions I'm working through right now so writing 
> test examples for individual end users isn't something I can do right now.
> 
> Robert.
> 
>  
> 
>  ------------------
> Post generated by Mail2Forum
[list=][/list] :'

------------------
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=61779#61779





_______________________________________________
osg-submissions mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org

Reply via email to