Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
G4MTBarrier Class Reference

#include <G4MTBarrier.hh>

Public Member Functions

 G4MTBarrier ()
 
virtual ~G4MTBarrier ()
 
 G4MTBarrier (const G4MTBarrier &)=delete
 
G4MTBarrieroperator= (const G4MTBarrier &)=delete
 
 G4MTBarrier (unsigned int numThreads)
 
void ThisWorkerReady ()
 
virtual void WaitForReadyWorkers ()
 
void SetActiveThreads (unsigned int val)
 
void ResetCounter ()
 
unsigned int GetCounter ()
 
void Wait ()
 
void ReleaseBarrier ()
 
void Wait (unsigned int numt)
 

Detailed Description

Definition at line 128 of file G4MTBarrier.hh.

Constructor & Destructor Documentation

G4MTBarrier::G4MTBarrier ( )
inline

Definition at line 131 of file G4MTBarrier.hh.

131 : G4MTBarrier(1) {}
virtual G4MTBarrier::~G4MTBarrier ( )
inlinevirtual

Definition at line 132 of file G4MTBarrier.hh.

132 {}
G4MTBarrier::G4MTBarrier ( const G4MTBarrier )
delete
G4MTBarrier::G4MTBarrier ( unsigned int  numThreads)

Definition at line 38 of file G4MTBarrier.cc.

38  :
39  m_numActiveThreads(numThreads),
40  m_counter(0),
41  m_mutex(G4MUTEX_INITIALIZER),
42  m_counterChanged(G4CONDITION_INITIALIZER),
43  m_continue(G4CONDITION_INITIALIZER)
44 {
45 #if defined(WIN32)
46  InitializeCriticalSection( &cs1 );
47  InitializeCriticalSection( &cs2 );
48 #endif
49 }
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
#define G4CONDITION_INITIALIZER
Definition: G4Threading.hh:190

Member Function Documentation

unsigned int G4MTBarrier::GetCounter ( )

Definition at line 116 of file G4MTBarrier.cc.

116  {
117  G4AutoLock l(&m_mutex);
118  const unsigned int result = m_counter;
119  return result;
120 }
G4double G4ParticleHPJENDLHEData::G4double result
G4MTBarrier& G4MTBarrier::operator= ( const G4MTBarrier )
delete
void G4MTBarrier::ReleaseBarrier ( )

Definition at line 97 of file G4MTBarrier.cc.

97  {
98  //Step-4: re-aquire lock and re-set shared resource for future re-use
99  G4AutoLock lock(&m_mutex);
100  m_counter = 0;
101  G4CONDITIONBROADCAST(&m_continue);
102 }
#define G4CONDITIONBROADCAST(cond)
Definition: G4Threading.hh:192

Here is the caller graph for this function:

void G4MTBarrier::ResetCounter ( )

Definition at line 111 of file G4MTBarrier.cc.

111  {
112  G4AutoLock l(&m_mutex);
113  m_counter = 0;
114 }

Here is the caller graph for this function:

void G4MTBarrier::SetActiveThreads ( unsigned int  val)
inline

Definition at line 142 of file G4MTBarrier.hh.

142 { m_numActiveThreads = val; }

Here is the caller graph for this function:

void G4MTBarrier::ThisWorkerReady ( )

Definition at line 51 of file G4MTBarrier.cc.

51  {
52  //Step-1: Worker acquires lock on shared resource (the counter)
53 #ifndef WIN32
54  G4AutoLock lock(&m_mutex);
55 #else
56  EnterCriticalSection( &cs1 );
57 #endif
58  //Step-2: Worker increases counter
59  ++m_counter;
60  //Step-3: Worker broadcasts that the counter has changed
61  G4CONDITIONBROADCAST(&m_counterChanged);
62  //Step-4: Worker waits on condition to continue
63 #ifndef WIN32
64  G4CONDITIONWAIT(&m_continue,&m_mutex);
65 #else
66 # ifdef G4MULTITHREADED
67  G4CONDITIONWAIT(&m_continue,&cs1);
68 # endif
69  LeaveCriticalSection(&cs1);
70 #endif
71 }
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191
#define G4CONDITIONBROADCAST(cond)
Definition: G4Threading.hh:192

Here is the caller graph for this function:

void G4MTBarrier::Wait ( )

Definition at line 73 of file G4MTBarrier.cc.

73  {
74  while (true)
75  {
76  //Step-2: Acquires lock on shared resource (the counter)
77 #ifndef WIN32
78  G4AutoLock lock(&m_mutex);
79 #else
80  EnterCriticalSection(&cs2);
81 #endif
82  //If the counter equals active threads, all threads are ready, exit the loop
83  if ( m_counter == m_numActiveThreads ) { break; }
84  //Step-3: Not all workers are ready, wait for the number to change
85  //before repeating the check
86 #ifdef WIN32
87 # ifdef G4MULTITHREADED
88  G4CONDITIONWAIT(&m_counterChanged,&cs2);
89 # endif
90  LeaveCriticalSection(&cs2);
91 #else
92  G4CONDITIONWAIT(&m_counterChanged,&m_mutex);
93 #endif
94  }
95 }
#define G4CONDITIONWAIT(cond, mutex)
Definition: G4Threading.hh:191

Here is the caller graph for this function:

void G4MTBarrier::Wait ( unsigned int  numt)
inline

Definition at line 147 of file G4MTBarrier.hh.

147  {
148  SetActiveThreads( numt );
149  Wait();
150  }
void SetActiveThreads(unsigned int val)
Definition: G4MTBarrier.hh:142
void Wait()
Definition: G4MTBarrier.cc:73

Here is the call graph for this function:

void G4MTBarrier::WaitForReadyWorkers ( )
virtual

Definition at line 104 of file G4MTBarrier.cc.

104  {
105  //Step-1: Master enters a loop to wait all workers to be ready
106  Wait();
107  //Done, all workers are ready, broadcast a continue signal
108  ReleaseBarrier();
109 }
void ReleaseBarrier()
Definition: G4MTBarrier.cc:97
void Wait()
Definition: G4MTBarrier.cc:73

Here is the call graph for this function:

Here is the caller graph for this function:


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