#include <base_thread_per.hh>
Public Member Functions | |
| PerThreadPtr (void) | |
| ~PerThreadPtr () | |
| T * | operator-> (void) |
| |
| T & | operator * (void) |
| |
| T * | PTR (void) |
| Limited-use. Explicitly get raw pointer. | |
Private Member Functions | |
| T * | NewPerThreadVar (void) |
Private Attributes | |
| pthread_key_t | mKey |
This class automatically allocates per-thread objects on the heap. The pointed-to class must have a default constructor.
PerThreadPtr is intended to be a class member. PerThreadPtr can be thought as a magic pointer that makes a new object local to a new thread.
Example: The 4 threads will animate 4 separate Ghosts. PerThreadPtr will detect that a new thread has started, and will allocate 4 Ghosts on the heap.
class Pacman { Pacman( void ) { RunThread(); RunThread(); RunThread(); RunThread(); } ~Pacman() { } CLASS_METHOD void RunThread( void ) { mGhost->Animate(); } PerThreadPtr<Ghost> mGhost; };
pthreads notes: pthreads just provides mapping between a thread and a POINTER. The application (this code) is responsible for allocating memory blocks on the heap for every thread. The Thread class allocates one large memory block for a new thread and deletes the whole block when the thread ends. PerThreadPtr sub-allocates the block and places new per-thread objects using C++ placement new.
| base::PerThreadPtr< T >::PerThreadPtr | ( | void | ) | [inline] |
| base::PerThreadPtr< T >::~PerThreadPtr | ( | ) | [inline] |
| T* base::PerThreadPtr< T >::NewPerThreadVar | ( | void | ) | [inline, private] |
| T* base::PerThreadPtr< T >::operator-> | ( | void | ) | [inline] |
| T& base::PerThreadPtr< T >::operator * | ( | void | ) | [inline] |
| T* base::PerThreadPtr< T >::PTR | ( | void | ) | [inline] |
Limited-use. Explicitly get raw pointer.
pthread_key_t base::PerThreadPtr< T >::mKey [private] |
Palomino 3D Engine documents generated by doxygen 1.5.3 on Fri Nov 23 11:26:20 2007