Hi,

On Tuesday 24 June 2008 07:02, Jean-Sébastien Guay wrote:
> > I'll let you know how it goes.
>
> Still a no go. I'm turning in for the night, but I'll try something else
> tomorrow.
>
> I'm considering splitting Atomic into a header and a .cpp file, so that
> windows.h can be included only in the implementation and not the header.
> That would fix it, since the problems I'm seeing are caused by the fact
> that windows.h is being included at the very top level of the include
> chain. Not sure if that has any other implications though. Thoughts?

Well, I try to summarize that somehow:

osg uses reference counting in many places.
These reference counts need to be thread safe in many cases. The most 
important ones aries in the multithreaded viewer code paths I guess. So 
everybody using a threaded viewer will benefit from that.

You have two options to make that thread safe.
* Either use a mutex that is held during modification (Relatively slow, 
involves even a system call per lock and one per unlock on many platforms).
* Use a single assembler instruction that guarantees that the modification 
happens atomically (Way faster).

Modifying that reference count happens very often. It happens that often that 
you observe execution speed improovements when you optimize that code path.
The best improovements will happen when you inline that reference counting 
stuff completely in the calling code. That also enables compiler 
optimizations so that in some cases the count modifications can be eliminated 
completely.
Therefore the Atomic stuff, which is inlined into code that is compiled even 
in code that just calls osg (more exact: that uses osg::Referenced::
{ref,unref}, that is used from osg::ref_ptr<T>). That means you need to 
include the atomic code into basically everything.
Therefore including Windows.h in Atomic.

The config header is just a way to tell the atomic integer class which 
implementation to use. This is basically due to the lack of an atomic type in 
the c++ standard (which is addressed in the next standard version btw).

When you want to inline the fast path of the reference counting stuff, you 
need to make sure that you pick up the right atomic increment implementation 
in Atomic which should match the one used when compiling osg. Therefore the 
Config header.
That's all.

GReetings

Mathias

-- 
Dr. Mathias Fröhlich, science + computing ag, Software Solutions
Hagellocher Weg 71-75, D-72070 Tuebingen, Germany
Phone: +49 7071 9457-268, Fax: +49 7071 9457-511
-- 
Vorstand/Board of Management:
Dr. Bernd Finkbeiner, Dr. Florian Geyer,
Dr. Roland Niemeier, Dr. Arno Steitz, Dr. Ingrid Zech
Vorsitzender des Aufsichtsrats/
Chairman of the Supervisory Board:
Prof. Dr. Hanns Ruder
Sitz/Registered Office: Tuebingen
Registergericht/Registration Court: Stuttgart
Registernummer/Commercial Register No.: HRB 382196 


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

Reply via email to