Geant4  10.02.p03
G4PDefSplitter< T > Class Template Reference

#include <G4PDefSplitter.hh>

Collaboration diagram for G4PDefSplitter< T >:

Public Member Functions

 G4PDefSplitter ()
 
G4int CreateSubInstance ()
 
void NewSubInstances ()
 
void FreeSlave ()
 
T * GetOffset ()
 
void UseWorkArea (T *newOffset)
 
T * FreeWorkArea ()
 

Public Attributes

G4PART_DLL G4ThreadLocalStatic G4int slavetotalspace
 
G4PART_DLL G4ThreadLocalStatic T * offset
 

Private Attributes

G4int totalobj
 
G4Mutex mutex
 

Detailed Description

template<class T>
class G4PDefSplitter< T >

Definition at line 53 of file G4PDefSplitter.hh.

Constructor & Destructor Documentation

◆ G4PDefSplitter()

template<class T >
G4PDefSplitter< T >::G4PDefSplitter ( )
inline

Definition at line 57 of file G4PDefSplitter.hh.

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

Member Function Documentation

◆ CreateSubInstance()

template<class T >
G4int G4PDefSplitter< T >::CreateSubInstance ( )
inline

Definition at line 62 of file G4PDefSplitter.hh.

66  {
67  G4AutoLock l(&mutex);
68  totalobj++;
70  {
71  l.unlock();
73  l.lock();
74  }
75  return (totalobj - 1);
76  }
G4PART_DLL G4ThreadLocalStatic G4int slavetotalspace
void NewSubInstances()
Here is the call graph for this function:

◆ FreeSlave()

template<class T >
void G4PDefSplitter< T >::FreeSlave ( )
inline

Definition at line 101 of file G4PDefSplitter.hh.

103  {
104  if (!offset) { return; }
105  free(offset);
106  offset = 0;
107  }
G4PART_DLL G4ThreadLocalStatic T * offset

◆ FreeWorkArea()

template<class T >
T* G4PDefSplitter< T >::FreeWorkArea ( )
inline

Definition at line 126 of file G4PDefSplitter.hh.

127  {
128  // Detach this thread from this Location
129  // The object which calls this method is responsible for it.
130  //
131  T* offsetRet= offset;
132 
133  offset= 0;
134 
135  return offsetRet;
136  }
G4PART_DLL G4ThreadLocalStatic T * offset

◆ GetOffset()

template<class T >
T* G4PDefSplitter< T >::GetOffset ( )
inline

Definition at line 110 of file G4PDefSplitter.hh.

110 { return offset; }
G4PART_DLL G4ThreadLocalStatic T * offset

◆ NewSubInstances()

template<class T >
void G4PDefSplitter< T >::NewSubInstances ( )
inline

Definition at line 78 of file G4PDefSplitter.hh.

82  {
83  G4AutoLock l(&mutex);
84  if (slavetotalspace >= totalobj) { return; }
85  G4int originaltotalspace = slavetotalspace;
86  slavetotalspace = totalobj + 512;
87  offset = (T *) realloc(offset, slavetotalspace * sizeof(T));
88 
89  if (offset == 0)
90  {
91  G4Exception("G4PDefSplitter::NewSubInstances()",
92  "OutOfMemory", FatalException, "Cannot malloc space!");
93  }
94 
95  for (G4int i = originaltotalspace; i < slavetotalspace; i++)
96  {
97  offset[i].initialize();
98  }
99  }
G4PART_DLL G4ThreadLocalStatic G4int slavetotalspace
int G4int
Definition: G4Types.hh:78
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4PART_DLL G4ThreadLocalStatic T * offset
Here is the call graph for this function:
Here is the caller graph for this function:

◆ UseWorkArea()

template<class T >
void G4PDefSplitter< T >::UseWorkArea ( T *  newOffset)
inline

Definition at line 112 of file G4PDefSplitter.hh.

113  {
114  // Use recycled work area - which was created previously
115  if( offset && offset!=newOffset )
116  {
117  G4Exception("G4PDefSplitter::UseWorkspace()",
118  "TwoWorkspaces", FatalException,
119  "Thread already has workspace - cannot use another.");
120  }
121  offset= newOffset;
122  // totalobj= numObjects;
123  // totalspace= numSpace;
124  }
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4PART_DLL G4ThreadLocalStatic T * offset
Here is the call graph for this function:

Member Data Documentation

◆ mutex

template<class T >
G4Mutex G4PDefSplitter< T >::mutex
private

Definition at line 146 of file G4PDefSplitter.hh.

◆ offset

template<class T >
G4PART_DLL G4ThreadLocalStatic T* G4PDefSplitter< T >::offset

Definition at line 141 of file G4PDefSplitter.hh.

◆ slavetotalspace

template<class T >
G4PART_DLL G4ThreadLocalStatic G4int G4PDefSplitter< T >::slavetotalspace

Definition at line 140 of file G4PDefSplitter.hh.

◆ totalobj

template<class T >
G4int G4PDefSplitter< T >::totalobj
private

Definition at line 145 of file G4PDefSplitter.hh.


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