Geant4  10.02.p03
G4ThreadLocalSingleton< T > Class Template Reference

#include <G4ThreadLocalSingleton.hh>

Inheritance diagram for G4ThreadLocalSingleton< T >:
Collaboration diagram for G4ThreadLocalSingleton< T >:

Public Member Functions

 G4ThreadLocalSingleton ()
 
 ~G4ThreadLocalSingleton ()
 
T * Instance () const
 

Private Member Functions

 G4ThreadLocalSingleton (G4ThreadLocalSingleton &rhs)
 
void Register (T *i) const
 
void Clear ()
 
- Private Member Functions inherited from G4Cache< T *>
 G4Cache ()
 
 G4Cache (const value_type &v)
 
 G4Cache (const G4Cache &rhs)
 
virtual ~G4Cache ()
 
value_typeGet () const
 
void Put (const value_type &val) const
 
value_type Pop ()
 
G4Cacheoperator= (const G4Cache &rhs)
 
const int & GetId () const
 

Private Attributes

std::list< T * > instances
 
G4Mutex listm
 

Friends

void G4AutoDelete::Register (T *)
 

Additional Inherited Members

- Private Types inherited from G4Cache< T *>
typedef T * value_type
 

Detailed Description

template<class T>
class G4ThreadLocalSingleton< T >

Definition at line 108 of file G4ThreadLocalSingleton.hh.

Constructor & Destructor Documentation

◆ G4ThreadLocalSingleton() [1/2]

template<class T >
G4ThreadLocalSingleton< T >::G4ThreadLocalSingleton ( )

Definition at line 135 of file G4ThreadLocalSingleton.hh.

135  : G4Cache<T*>() {
137  G4Cache<T*>::Put(static_cast<T*>(0));
138 }
void Put(const value_type &val) const
Definition: G4Cache.hh:286
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:177
Here is the call graph for this function:

◆ ~G4ThreadLocalSingleton()

template<class T >
G4ThreadLocalSingleton< T >::~G4ThreadLocalSingleton ( )

Definition at line 141 of file G4ThreadLocalSingleton.hh.

141  {
143  Clear();
144 }
#define G4MUTEXDESTROY(mutex)
Definition: G4Threading.hh:178
Here is the call graph for this function:

◆ G4ThreadLocalSingleton() [2/2]

template<class T >
G4ThreadLocalSingleton< T >::G4ThreadLocalSingleton ( G4ThreadLocalSingleton< T > &  rhs)
private

Definition at line 158 of file G4ThreadLocalSingleton.hh.

158 {}

Member Function Documentation

◆ Clear()

template<class T >
void G4ThreadLocalSingleton< T >::Clear ( )
private

Definition at line 167 of file G4ThreadLocalSingleton.hh.

167  {
168  G4AutoLock l(&listm);
169  while ( ! instances.empty() )
170  {
171  T* thisinst = instances.front();
172  instances.pop_front();
173  if ( thisinst != 0 ) delete thisinst;
174  }
175  }
Here is the caller graph for this function:

◆ Instance()

template<class T >
T * G4ThreadLocalSingleton< T >::Instance ( void  ) const

Definition at line 147 of file G4ThreadLocalSingleton.hh.

147  {
148  T* instance = G4Cache<T*>::Get();
149  if ( instance == static_cast<T*>(0) ) {
150  instance = new T;
151  G4Cache<T*>::Put( instance );
152  Register(instance);
153  }
154  return instance;
155  }
void Put(const value_type &val) const
Definition: G4Cache.hh:286
value_type & Get() const
Definition: G4Cache.hh:282
static MCTruthManager * instance
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Register()

template<class T >
void G4ThreadLocalSingleton< T >::Register ( T *  i) const
private

Definition at line 160 of file G4ThreadLocalSingleton.hh.

160  {
161  G4AutoLock l(&listm);
162  instances.push_back(i);
163 }
Here is the caller graph for this function:

Friends And Related Function Documentation

◆ G4AutoDelete::Register

template<class T>
void G4AutoDelete::Register ( T *  )
friend

Member Data Documentation

◆ instances

template<class T>
std::list<T*> G4ThreadLocalSingleton< T >::instances
mutableprivate

Definition at line 125 of file G4ThreadLocalSingleton.hh.

◆ listm

template<class T>
G4Mutex G4ThreadLocalSingleton< T >::listm
mutableprivate

Definition at line 126 of file G4ThreadLocalSingleton.hh.


The documentation for this class was generated from the following file: