Geant4-11
Public Member Functions | Static Public Member Functions | Private Attributes
G4PDefManager Class Reference

#include <G4PDefManager.hh>

Public Member Functions

G4int CreateSubInstance ()
 
void FreeSlave ()
 
G4PDefDataFreeWorkArea ()
 
 G4PDefManager ()
 
G4PDefDataGetOffset ()
 
void NewSubInstances ()
 
void UseWorkArea (G4PDefData *newOffset)
 

Static Public Member Functions

static G4PART_DLL G4PDefData *& offset ()
 
static G4PART_DLL G4intslavetotalspace ()
 

Private Attributes

G4Mutex mutex
 
G4int totalobj
 

Detailed Description

Definition at line 83 of file G4PDefManager.hh.

Constructor & Destructor Documentation

◆ G4PDefManager()

G4PDefManager::G4PDefManager ( )

Definition at line 57 of file G4PDefManager.cc.

57 : totalobj(0)
58{
60}
#define G4MUTEXINIT(mutex)
Definition: G4Threading.hh:87

References G4MUTEXINIT.

Member Function Documentation

◆ CreateSubInstance()

G4int G4PDefManager::CreateSubInstance ( )

Definition at line 62 of file G4PDefManager.cc.

66{
67 G4AutoLock l(&mutex);
68 ++totalobj;
70 {
71 l.unlock();
73 l.lock();
74 }
75 return (totalobj - 1);
76}
static G4PART_DLL G4int & slavetotalspace()
void NewSubInstances()

References G4TemplateAutoLock< _Mutex_t >::lock(), NewSubInstances(), slavetotalspace(), totalobj, and G4TemplateAutoLock< _Mutex_t >::unlock().

Referenced by G4ParticleDefinition::SetParticleDefinitionID().

◆ FreeSlave()

void G4PDefManager::FreeSlave ( )

Definition at line 101 of file G4PDefManager.cc.

103{
104 if (offset() == nullptr) { return; }
105 free(offset());
106 offset() = nullptr;
107}
static G4PART_DLL G4PDefData *& offset()

References free, and offset().

Referenced by G4ParticleDefinition::Clean(), and G4ParticlesWorkspace::DestroyWorkspace().

◆ FreeWorkArea()

G4PDefData * G4PDefManager::FreeWorkArea ( )

Definition at line 126 of file G4PDefManager.cc.

129{
130 G4PDefData* offsetRet = offset();
131 offset() = nullptr;
132 return offsetRet;
133}

References offset().

◆ GetOffset()

G4PDefData * G4PDefManager::GetOffset ( )

Definition at line 109 of file G4PDefManager.cc.

110{
111 return offset();
112}

References offset().

Referenced by G4ParticlesWorkspace::G4ParticlesWorkspace().

◆ NewSubInstances()

void G4PDefManager::NewSubInstances ( )

Definition at line 78 of file G4PDefManager.cc.

82{
83 G4AutoLock l(&mutex);
84 if (slavetotalspace() >= totalobj) { return; }
85 G4int originaltotalspace = slavetotalspace();
86 slavetotalspace() = totalobj + 512;
87 offset() = (G4PDefData *) realloc(offset(),
88 slavetotalspace() * sizeof(G4PDefData));
89 if (offset() == nullptr)
90 {
91 G4Exception("G4PDefManager::NewSubInstances()",
92 "OutOfMemory", FatalException, "Cannot malloc space!");
93 }
94
95 for (G4int i = originaltotalspace; i < slavetotalspace(); ++i)
96 {
97 offset()[i].initialize();
98 }
99}
@ FatalException
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
int G4int
Definition: G4Types.hh:85
void initialize()

References FatalException, G4Exception(), G4PDefData::initialize(), offset(), slavetotalspace(), and totalobj.

Referenced by CreateSubInstance(), and G4ParticlesWorkspace::InitialiseWorkspace().

◆ offset()

G4PDefData *& G4PDefManager::offset ( )
static

Definition at line 51 of file G4PDefManager.cc.

52{
53 G4ThreadLocalStatic G4PDefData* _instance = nullptr;
54 return _instance;
55}
#define G4ThreadLocalStatic
Definition: tls.hh:76

References G4ThreadLocalStatic.

Referenced by FreeSlave(), FreeWorkArea(), GetOffset(), NewSubInstances(), and UseWorkArea().

◆ slavetotalspace()

G4int & G4PDefManager::slavetotalspace ( )
static

Definition at line 45 of file G4PDefManager.cc.

46{
47 G4ThreadLocalStatic G4int _instance = 0;
48 return _instance;
49}

References G4ThreadLocalStatic.

Referenced by CreateSubInstance(), NewSubInstances(), and G4VUserPhysicsList::RemoveProcessManager().

◆ UseWorkArea()

void G4PDefManager::UseWorkArea ( G4PDefData newOffset)

Definition at line 114 of file G4PDefManager.cc.

116{
117 if( (offset() != nullptr) && (offset() != newOffset) )
118 {
119 G4Exception("G4PDefManager::UseWorkspace()",
120 "InvalidCondition", FatalException,
121 "Thread already has workspace - cannot use another.");
122 }
123 offset() = newOffset;
124}

References FatalException, G4Exception(), and offset().

Referenced by G4ParticlesWorkspace::ReleaseWorkspace(), and G4ParticlesWorkspace::UseWorkspace().

Field Documentation

◆ mutex

G4Mutex G4PDefManager::mutex
private

Definition at line 114 of file G4PDefManager.hh.

◆ totalobj

G4int G4PDefManager::totalobj
private

Definition at line 113 of file G4PDefManager.hh.

Referenced by CreateSubInstance(), and NewSubInstances().


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