Geant4 11.3.0
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4Cache< VALTYPE > Class Template Reference

#include <G4Cache.hh>

+ Inheritance diagram for G4Cache< VALTYPE >:

Public Types

using value_type = VALTYPE
 

Public Member Functions

 G4Cache ()
 
 G4Cache (const value_type &v)
 
virtual ~G4Cache ()
 
value_typeGet () const
 
void Put (const value_type &val) const
 
value_type Pop ()
 
 G4Cache (const G4Cache &rhs)
 
G4Cacheoperator= (const G4Cache &rhs)
 

Protected Member Functions

const G4intGetId () const
 

Detailed Description

template<class VALTYPE>
class G4Cache< VALTYPE >

Definition at line 88 of file G4Cache.hh.

Member Typedef Documentation

◆ value_type

template<class VALTYPE>
using G4Cache< VALTYPE >::value_type = VALTYPE

Definition at line 91 of file G4Cache.hh.

Constructor & Destructor Documentation

◆ G4Cache() [1/3]

template<class V>
G4Cache< V >::G4Cache ( )

Definition at line 210 of file G4Cache.hh.

211{
213 id = instancesctr++;
214#ifdef g4cdebug
215 std::cout << "G4Cache id: " << id << std::endl;
216#endif
217}
G4Cache()
Definition G4Cache.hh:210

Referenced by G4Cache(), G4Cache(), operator=(), and ~G4Cache().

◆ G4Cache() [2/3]

template<class VALTYPE>
G4Cache< VALTYPE >::G4Cache ( const value_type & v)

◆ ~G4Cache()

template<class V>
G4Cache< V >::~G4Cache ( )
virtual

Definition at line 270 of file G4Cache.hh.

271{
272#ifdef g4cdebug
273 std::cout << "~G4Cache id: " << id << std::endl;
274#endif
275 // don't automatically lock --> wait until we can catch an error
276 // without scoping the G4AutoLock
277 //
279
280 // sometimes the mutex is unavailable in destructors so
281 // try to lock the associated mutex, but catch if it fails
282 try
283 {
284 // a system_error in lock means that the mutex is unavailable
285 // we want to throw the error that comes from locking an unavailable
286 // mutex so that we know there is a memory leak
287 // if the mutex is valid, this will hold until the other thread finishes
288 //
289 l.lock();
290 } catch(std::system_error& e)
291 {
292 // the error that comes from locking an unavailable mutex
293#ifdef G4VERBOSE
294 G4cout << "Non-critical error: mutex lock failure in ~G4Cache<"
295 << typeid(V).name() << ">. " << G4endl
296 << "If the RunManagerKernel has been deleted, it failed to "
297 << "delete an allocated resource" << G4endl
298 << "and this destructor is being called after the statics "
299 << "were destroyed." << G4endl;
300 G4cout << "Exception: [code: " << e.code() << "] caught: " << e.what()
301 << G4endl;
302#endif
303 }
304 ++dstrctr;
305 G4bool last = (dstrctr == instancesctr);
306 theCache.Destroy(id, last);
307 if(last)
308 {
309 instancesctr.store(0);
310 dstrctr.store(0);
311 }
312}

◆ G4Cache() [3/3]

template<class VALTYPE>
G4Cache< VALTYPE >::G4Cache ( const G4Cache< VALTYPE > & rhs)

Member Function Documentation

◆ Get()

◆ GetId()

template<class VALTYPE>
const G4int & G4Cache< VALTYPE >::GetId ( ) const
inlineprotected

Definition at line 116 of file G4Cache.hh.

116{ return id; }

Referenced by G4MapCache< KEYTYPE, VALTYPE >::~G4MapCache().

◆ operator=()

template<class VALTYPE>
G4Cache< V > & G4Cache< V >::operator= ( const G4Cache< VALTYPE > & rhs)

Definition at line 241 of file G4Cache.hh.

242{
243 if(this == &rhs)
244 return *this;
245
246 // Force copy of cached data
247 //
248 V aCopy = rhs.GetCache();
249 Put(aCopy);
250
251#ifdef g4cdebug
252 std::cout << "Assignement operator with id: " << id << std::endl;
253#endif
254 return *this;
255}
void Put(const value_type &val) const
Definition G4Cache.hh:321

◆ Pop()

template<class V>
V G4Cache< V >::Pop ( )
inline

Definition at line 328 of file G4Cache.hh.

329{
330 return GetCache();
331}

◆ Put()

template<class VALTYPE>
void G4Cache< V >::Put ( const value_type & val) const
inline

Definition at line 321 of file G4Cache.hh.

322{
323 GetCache() = val;
324}

Referenced by G4ThreadLocalSingleton< T >::G4ThreadLocalSingleton(), G4ThreadLocalSingleton< T >::Instance(), and operator=().


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