#include <globalPointerRegistry.h>
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 |
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.
|
Definition at line 122 of file globalPointerRegistry.h. |
|
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. |
|
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(). |
|
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(). |
|
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. |
|
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. |
|
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(). |
|
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. |
|
Definition at line 30 of file globalPointerRegistry.cxx. |
|
Definition at line 123 of file globalPointerRegistry.h. |