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




Attachments: 
http://forum.openscenegraph.org//files/databasepagercallback_submission_112.zip


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

Reply via email to