Geant4-11
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends
G4ThreadLocalSingleton< T > Class Template Reference

#include <G4ThreadLocalSingleton.hh>

Inheritance diagram for G4ThreadLocalSingleton< T >:
G4Cache< T * >

Public Member Functions

 G4ThreadLocalSingleton ()
 
 G4ThreadLocalSingleton (const G4ThreadLocalSingleton &)=delete
 
 G4ThreadLocalSingleton (G4ThreadLocalSingleton &&)=default
 
T * Instance () const
 
G4ThreadLocalSingletonoperator= (const G4ThreadLocalSingleton &)=delete
 
G4ThreadLocalSingletonoperator= (G4ThreadLocalSingleton &&)=default
 
 ~G4ThreadLocalSingleton ()
 

Private Types

typedef T * value_type
 

Private Member Functions

void Clear ()
 
value_typeGet () const
 
value_typeGetCache () const
 
const G4intGetId () const
 
value_type Pop ()
 
void Put (const value_type &val) const
 
void Register (T *i) const
 

Private Attributes

G4int id
 
std::list< T * > instances
 
G4Mutex listm
 
G4CacheReference< value_typetheCache
 

Static Private Attributes

static std::atomic< unsigned int > dstrctr
 
static std::atomic< unsigned int > instancesctr
 

Friends

void G4AutoDelete::Register (T *)
 

Detailed Description

template<class T>
class G4ThreadLocalSingleton< T >

Definition at line 145 of file G4ThreadLocalSingleton.hh.

Member Typedef Documentation

◆ value_type

typedef T * G4Cache< T * >::value_type
inherited

Definition at line 91 of file G4Cache.hh.

Constructor & Destructor Documentation

◆ G4ThreadLocalSingleton() [1/3]

Definition at line 178 of file G4ThreadLocalSingleton.hh.

179 : G4Cache<T*>()
180{
182 G4Cache<T*>::Put(static_cast<T*>(0));
183 // Uncomment below to find the origin of where instantiation happened
184 /*
185 auto bt = G4Backtrace::GetDemangled<4, 1>(
186 [](const char* cstr) { return std::string{ cstr }; });
187 std::cout << "Backtrace to G4ThreadLocalSingleton<"
188 << G4Demangle<T>().c_str() << ">:\n";
189 for(auto& itr : bt)
190 {
191 if(!itr.empty())
192 std::cout << "\t" << itr << "\n";
193 }
194 */
196 printf("Deleting G4ThreadLocalSingletons for type %s ...\n",
197 G4Demangle<T>().c_str());
198 this->Clear();
199 });
200}
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:87
void Put(const value_type &val) const
Definition: G4Cache.hh:321

References G4ThreadLocalSingleton< T >::Clear(), G4MUTEXINIT, G4ThreadLocalSingleton< T >::listm, and G4Cache< VALTYPE >::Put().

◆ ~G4ThreadLocalSingleton()

Definition at line 203 of file G4ThreadLocalSingleton.hh.

204{
205 Clear();
207}
#define G4MUTEXDESTROY(mutex)
Definition: G4Threading.hh:90

References G4MUTEXDESTROY.

◆ G4ThreadLocalSingleton() [2/3]

template<class T >
G4ThreadLocalSingleton< T >::G4ThreadLocalSingleton ( const G4ThreadLocalSingleton< T > &  )
delete

◆ G4ThreadLocalSingleton() [3/3]

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

Member Function Documentation

◆ Clear()

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

Definition at line 230 of file G4ThreadLocalSingleton.hh.

231{
232 if(instances.empty())
233 return;
234 G4AutoLock l(&listm);
235 while(!instances.empty())
236 {
237 T* thisinst = instances.front();
238 instances.pop_front();
239 delete thisinst;
240 }
241}

Referenced by G4ThreadLocalSingleton< T >::G4ThreadLocalSingleton(), and G4TaskRunManager::~G4TaskRunManager().

◆ Get()

V & G4Cache< V >::Get
inlineinherited

Definition at line 103 of file G4Cache.hh.

316{
317 return GetCache();
318}
value_type & GetCache() const
Definition: G4Cache.hh:124

◆ GetCache()

value_type & G4Cache< T * >::GetCache ( ) const
inlineprivateinherited

Definition at line 124 of file G4Cache.hh.

125 {
127 return theCache.GetCache(id);
128 }
VALTYPE & GetCache(unsigned int id) const
void Initialize(unsigned int id)
G4CacheReference< value_type > theCache
Definition: G4Cache.hh:120

◆ GetId()

const G4int & G4Cache< T * >::GetId ( ) const
inlineprotectedinherited

Definition at line 116 of file G4Cache.hh.

116{ return id; }

◆ Instance()

template<class T >
T * G4ThreadLocalSingleton< T >::Instance

◆ operator=() [1/2]

template<class T >
G4ThreadLocalSingleton & G4ThreadLocalSingleton< T >::operator= ( const G4ThreadLocalSingleton< T > &  )
delete

◆ operator=() [2/2]

template<class T >
G4ThreadLocalSingleton & G4ThreadLocalSingleton< T >::operator= ( G4ThreadLocalSingleton< T > &&  )
default

◆ Pop()

V G4Cache< V >::Pop
inlineinherited

Definition at line 109 of file G4Cache.hh.

329{
330 return GetCache();
331}

◆ Put()

void G4Cache< V >::Put ( const value_type val) const
inlineinherited

Definition at line 106 of file G4Cache.hh.

322{
323 GetCache() = val;
324}

◆ Register()

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

Definition at line 223 of file G4ThreadLocalSingleton.hh.

224{
225 G4AutoLock l(&listm);
226 instances.push_back(i);
227}

Referenced by G4AutoDelete::Register().

Friends And Related Function Documentation

◆ G4AutoDelete::Register

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

Field Documentation

◆ dstrctr

std::atomic< unsigned int > G4Cache< V >::dstrctr
staticprivateinherited

Definition at line 122 of file G4Cache.hh.

◆ id

G4int G4Cache< T * >::id
privateinherited

Definition at line 119 of file G4Cache.hh.

◆ instances

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

Definition at line 169 of file G4ThreadLocalSingleton.hh.

◆ instancesctr

std::atomic< unsigned int > G4Cache< V >::instancesctr
staticprivateinherited

Definition at line 121 of file G4Cache.hh.

◆ listm

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

◆ theCache

G4CacheReference<value_type> G4Cache< T * >::theCache
mutableprivateinherited

Definition at line 120 of file G4Cache.hh.


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