Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

GlobalPointerRegistry Class Reference

This class maintains a one-to-one mapping from TypeHandle to a void * pointer. More...

#include <globalPointerRegistry.h>

List of all members.

Static Public Member Functions

void * get_pointer (TypeHandle type)
 Returns the pointer associated with the indicated TypeHandle, if any.

void store_pointer (TypeHandle type, void *ptr)
 Associates the given pointer with the indicated TypeHandle.

void clear_pointer (TypeHandle type)
 Removes the association of the given pointer with the indicated TypeHandle.


Private Types

typedef pmap< TypeHandle,
void * > 
Pointers

Private Member Functions

void * ns_get_pointer (TypeHandle type) const
 Returns the pointer associated with the indicated TypeHandle, if any.

void ns_store_pointer (TypeHandle type, void *ptr)
 Associates the given pointer with the indicated TypeHandle.

void ns_clear_pointer (TypeHandle type)
 Removes the association of the given pointer with the indicated TypeHandle.


Static Private Member Functions

GlobalPointerRegistry * get_global_ptr ()
 Returns a pointer to the single GlobalPointerRegistry object.


Private Attributes

Pointers _pointers

Static Private Attributes

GlobalPointerRegistry * _global_ptr


Detailed Description

This class maintains a one-to-one mapping from TypeHandle to a void * pointer.

Its purpose is to store a pointer to some class data for a given class.

Normally, one would simply use a static data member to store class data. However, when the static data is associated with a template class, the dynamic loader may have difficulty in properly resolving the statics.

Consider: class foo<int> defines a static member, _a. There should be only one instance of _a shared between all instances of foo<int>, and there will be a different instance of _a shared between all instances of foo<float>.

Now suppose that two different shared libraries instantiate foo<int>. In each .so, there exists a different foo<int>::_a. It is the loader's job to recognize this and collapse them together when both libraries are loaded. This usually works, but sometimes it doesn't, and you end up with two different instances of foo<int>::_a; some functions see one instance, while others see the other. We have particularly seen this problem occur under Linux with gcc.

This class attempts to circumvent the problem by managing pointers to data based on TypeHandle. Since the TypeHandle will already be unique based on the string name supplied to the init_type() function, it can be used to differentiate foo<int> from foo<float>, while allowing different instances of foo<int> to guarantee that they share the same static data.

Definition at line 106 of file globalPointerRegistry.h.


Member Typedef Documentation

typedef pmap<TypeHandle, void *> GlobalPointerRegistry::Pointers [private]
 

Definition at line 122 of file globalPointerRegistry.h.


Member Function Documentation

void GlobalPointerRegistry::clear_pointer TypeHandle  type  )  [inline, static]
 

Removes the association of the given pointer with the indicated TypeHandle.

Subsequent calls to get_pointer() with this TypeHandle will return NULL, until another call to store_pointer() is made.

Definition at line 76 of file globalPointerRegistry.I.

GlobalPointerRegistry * GlobalPointerRegistry::get_global_ptr  )  [inline, static, private]
 

Returns a pointer to the single GlobalPointerRegistry object.

If the object does not yet exist, creates it. This indirection is used instead of making all the data members of GlobalPointerRegistry static, so that we don't have to worry about order dependency during static init time.

Definition at line 100 of file globalPointerRegistry.I.

Referenced by get_pointer().

void * GlobalPointerRegistry::get_pointer TypeHandle  type  )  [inline, static]
 

Returns the pointer associated with the indicated TypeHandle, if any.

If no pointer has yet been associated, returns NULL.

Definition at line 36 of file globalPointerRegistry.I.

References get_global_ptr(), INLINE, and ns_store_pointer().

void GlobalPointerRegistry::ns_clear_pointer TypeHandle  type  )  [private]
 

Removes the association of the given pointer with the indicated TypeHandle.

Subsequent calls to get_pointer() with this TypeHandle will return NULL, until another call to store_pointer() is made.

Definition at line 120 of file globalPointerRegistry.cxx.

void * GlobalPointerRegistry::ns_get_pointer TypeHandle  type  )  const [private]
 

Returns the pointer associated with the indicated TypeHandle, if any.

If no pointer has yet been associated, returns NULL.

Definition at line 45 of file globalPointerRegistry.cxx.

References NULL.

void GlobalPointerRegistry::ns_store_pointer TypeHandle  type,
void *  ptr
[private]
 

Associates the given pointer with the indicated TypeHandle.

It is an error to call this with a NULL pointer, or to call this function more than once with a given TypeHandle (without first calling clear_pointer).

Definition at line 76 of file globalPointerRegistry.cxx.

Referenced by get_pointer().

void GlobalPointerRegistry::store_pointer TypeHandle  type,
void *  ptr
[inline, static]
 

Associates the given pointer with the indicated TypeHandle.

It is an error to call this with a NULL pointer, or to call this function more than once with a given TypeHandle (without first calling clear_pointer).

Definition at line 57 of file globalPointerRegistry.I.


Member Data Documentation

GlobalPointerRegistry * GlobalPointerRegistry::_global_ptr [static, private]
 

Definition at line 30 of file globalPointerRegistry.cxx.

Pointers GlobalPointerRegistry::_pointers [private]
 

Definition at line 123 of file globalPointerRegistry.h.


The documentation for this class was generated from the following files:
Generated on Fri May 2 00:51:12 2003 for Panda by doxygen1.3