Hi Robert,
I tried out your proposals, but none of them worked!

Subclassing does not work, because addDatabaseThread() is called from the 
constructor of DatabasePager and calls therefore 
DatabasePager::addDatabaseThread() instead my overrided method.

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.

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...

Cheers
Alois



robertosfield wrote:
> Hi WeSee,
> 
> 
> Sorry for the slow reply, been busy working so had to pause reviewing 
> submissions.  I have just done a review of the your suggested additional of 
> DatabasePagerCallback and the original code and believe the callback should 
> not be required as the functionality you want should already be possible with 
> the existing version of the DatabasePager.
> 
> 
> In the DatabasePager the nsigned int 
> DatabasePager::addDatabaseThread(DatabaseThread::Mode mode, const 
> std::string& name) is virtual, and this is the method that creates the 
> DatabaseThread objects and assigns them to the DatabasePager.  By subclassing 
> from DatabasePager and overriding this method you could implement custom 
> creation of threads and assignment of CPU affinity.
> 
> 
> Another approach would be to get the DatabaseThread that have been assigned 
> to the DatabasePager via the DatabasePager::getDatabaseThread(i) method and 
> set the affinity from this.
> 
> Robert,
> 
> 
> 
> On 12 August 2014 14:33, We See < ()> wrote:
> 
> > Hi Robert,
> > 
> > you are right, I was very egoistic and posted a solution just solving my 
> > problem. I went one step back and looked through the framework-glasses. The 
> > solution I now present, works with a newly introduced 
> > database-pager-callback. See the attached files, because a code-file says 
> > more than thousand words, but here are some explanations anyway:
> > 
> > This changes I made in DatabasePager:
> > 
> > Code:
> > 
> > class OSGDB_EXPORT DatabasePagerCallback : public virtual osg::Referenced
> > {
> >   public:
> >     virtual DatabaseThread* createDatabaseThread(DatabasePager* pager, 
> > DatabaseThread::Mode mode, const std::string& name) = 0;
> >     virtual DatabaseThread* cloneDatabaseThread(const DatabaseThread& dt, 
> > DatabasePager* pager) = 0;
> > 
> >   protected:
> >     virtual ~DatabasePagerCallback() {}
> > };
> > 
> > /** Set the database-pager callback to use in place of the default 
> > database-pager calls.*/
> > static void setDatabasePagerCallback( DatabasePagerCallback* cb) { 
> > _databasePagerCallback = cb; }
> > 
> > /** Get the database-pager callback.*/
> > static DatabasePagerCallback* getDatabasePagerCallback() { return 
> > _databasePagerCallback.get(); }
> > 
> > static osg::ref_ptr<DatabasePagerCallback> _databasePagerCallback;
> > 
> > 
> > 
> > 
> > In DatabasePager::addDatabaseThread(), createDatabaseThread() will be 
> > called, if the callback is set. So we can introduce our own database-thread 
> > derived from DatabaseThread, where we could override the virtual methods, 
> > like run():
> > 
> > Code:
> > 
> > DatabaseThread* thread = 0;
> > if (_databasePagerCallback.valid()) thread = 
> > _databasePagerCallback->createDatabaseThread(this, mode, name);
> > else thread = new DatabaseThread(this, mode, name);
> > 
> > 
> > 
> > 
> > In the copy-constructor DatabasePager::DatabasePager(const DatabasePager& 
> > rhs), we call cloneDatabaseThread(), if the callback is present.
> > 
> > With this callback we can do very much things, therefore it is ideal for a 
> > framework like OSG is.
> > 
> > Here an example, how I use it to set the CPU:
> > 
> > 
> > Code:
> > 
> > class OSGDB_EXPORT MyDatabaseThread : public 
> > osgDB::DatabasePager::DatabaseThread
> > {
> >   public:
> >     MyDatabaseThread(osgDB::DatabasePager* pager, Mode mode, const 
> > std::string& name)
> >         : osgDB::DatabasePager::DatabaseThread(pager, mode, name) {}
> > 
> >     MyDatabaseThread(const MyDatabaseThread& dt, osgDB::DatabasePager* 
> > pager)
> >         : osgDB::DatabasePager::DatabaseThread(dt, pager) {}
> > 
> >     virtual ~MyDatabaseThread() {}
> > 
> >     virtual void run()
> >     {
> >       OpenThreads::SetProcessorAffinityOfCurrentThread(2);
> >       osgDB::DatabasePager::DatabaseThread::run();
> >     }
> > };
> > 
> > class MyDatabasePagerCallback : public virtual 
> > osgDB::DatabasePager::DatabasePagerCallback
> > {
> >   public:
> >     virtual osgDB::DatabasePager::DatabaseThread* 
> > createDatabaseThread(osgDB::DatabasePager* pager, 
> > osgDB::DatabasePager::DatabaseThread::Mode mode, const std::string& name)
> >     {
> >       return new MyDatabaseThread(pager, mode, name);
> >     };
> >     virtual osgDB::DatabasePager::DatabaseThread* cloneDatabaseThread(const 
> > osgDB::DatabasePager::DatabaseThread& dt, osgDB::DatabasePager* pager)
> >     {
> >       return new MyDatabaseThread((MyDatabaseThread&)dt, pager);
> >     }
> > 
> >   protected:
> >     virtual ~MyDatabasePagerCallback() {};
> > };
> > 
> > osgDB::DatabasePager::setDatabasePagerCallback(new MyDatabasePagerCallback);
> > 
> > 
> > 
> > 
> > I hope you are as satisfied as I am with this solution and could merge it.
> > 
> > Thank you!
> > 
> > Cheers,
> > WeSee
> > 
> > ------------------
> > Read this topic online here:
> > http://forum.openscenegraph.org/viewtopic.php?p=60640#60640 
> > (http://forum.openscenegraph.org/viewtopic.php?p=60640#60640)
> > 
> > 
> > 
> > 
> > Attachments:
> > http://forum.openscenegraph.org//files/databasepagercallback_submission_112.zip
> >  
> > (http://forum.openscenegraph.org//files/databasepagercallback_submission_112.zip)
> > 
> > 
> > _______________________________________________
> > osg-submissions mailing list
> >  ()
> > http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org
> >  
> > (http://lists.openscenegraph.org/listinfo.cgi/osg-submissions-openscenegraph.org)
> > 
> > 
> > 
> 
> 
>  ------------------
> Post generated by Mail2Forum


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





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

Reply via email to