Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::Singleton Class Template Reference

You can use this coolio class to make a singleton, just inherit like so... More...

#include <Singleton.h>

Inheritance diagram for vpr::Singleton:

Inheritance graph
[legend]
List of all members.

Static Public Methods

singleClass * instance (void)
 NOTE: currently, func is thread safe after first call to instance(). More...


Protected Methods

 Singleton ()
 Don't create a singleton with new! use instance(). More...

virtual ~Singleton ()
 don't delete a singleton! More...


Detailed Description

template<class singleClass>
class vpr::Singleton< singleClass >

You can use this coolio class to make a singleton, just inherit like so...

class myClass : public vpr::Singleton<myClass>

Definition at line 107 of file Singleton.h.


Constructor & Destructor Documentation

template<class singleClass>
vpr::Singleton< singleClass >::Singleton   [inline, protected]
 

Don't create a singleton with new! use instance().

Definition at line 141 of file Singleton.h.

00142       {
00143       }

template<class singleClass>
virtual vpr::Singleton< singleClass >::~Singleton   [inline, protected, virtual]
 

don't delete a singleton!

Definition at line 146 of file Singleton.h.

00147       {
00148       }


Member Function Documentation

template<class singleClass>
singleClass* vpr::Singleton< singleClass >::instance void    [inline, static]
 

NOTE: currently, func is thread safe after first call to instance().

if first call to instance happens multiple times simultaneously then don't be surprised when something dies because of a mutex.. this bug can be caused by spawning two threads immediately after entering main()

Definition at line 117 of file Singleton.h.

00118       {                                                 
00119          // WARNING! race condition possibility, creation of static vars 
00120          // are not thread safe.  This is only an issue when creating
00121          // your first thread, since it uses a singleton thread manager,
00122          // the two threads might both try to call instance at the same time
00123          // which then the creation of the following mutex would not be certain.
00124          static vpr::Mutex singleton_lock1;       
00125          static singleClass* the_instance1 = NULL;   
00126                                      
00127          if (the_instance1 == NULL)                 
00128          {                                            
00129             vpr::Guard<vpr::Mutex> guard( singleton_lock1 );
00130             if (the_instance1 == NULL)        
00131             { the_instance1 = new singleClass; }         
00132          }                                      
00133          return the_instance1;                     
00134       }


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:47:18 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002