Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
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 122 of file G4MTBarrier.hh.

Constructor & Destructor Documentation

◆ G4MTBarrier() [1/3]

G4MTBarrier::G4MTBarrier ( )
inline

Definition at line 125 of file G4MTBarrier.hh.

126 : G4MTBarrier(1)
127 {}

◆ ~G4MTBarrier()

virtual G4MTBarrier::~G4MTBarrier ( )
inlinevirtual

Definition at line 128 of file G4MTBarrier.hh.

128{}

◆ G4MTBarrier() [2/3]

G4MTBarrier::G4MTBarrier ( const G4MTBarrier & )
delete

◆ G4MTBarrier() [3/3]

G4MTBarrier::G4MTBarrier ( unsigned int numThreads)

Definition at line 35 of file G4MTBarrier.cc.

36 : m_numActiveThreads(numThreads)
37{}

Member Function Documentation

◆ GetCounter()

unsigned int G4MTBarrier::GetCounter ( )

Definition at line 97 of file G4MTBarrier.cc.

98{
99 G4AutoLock l(&m_mutex);
100 const unsigned int result = m_counter;
101 return result;
102}

◆ operator=()

G4MTBarrier & G4MTBarrier::operator= ( const G4MTBarrier & )
delete

◆ ReleaseBarrier()

void G4MTBarrier::ReleaseBarrier ( )

Definition at line 72 of file G4MTBarrier.cc.

73{
74 // Step-4: re-aquire lock and re-set shared resource for future re-use
75 G4AutoLock lock(&m_mutex);
76 m_counter = 0;
77 G4CONDITIONBROADCAST(&m_continue);
78}
#define G4CONDITIONBROADCAST(cond)

Referenced by G4MTRunManager::NewActionRequest(), G4MTRunManager::WaitForEndEventLoopWorkers(), WaitForReadyWorkers(), and G4MTRunManager::WaitForReadyWorkers().

◆ ResetCounter()

void G4MTBarrier::ResetCounter ( )

Definition at line 90 of file G4MTBarrier.cc.

91{
92 G4AutoLock l(&m_mutex);
93 m_counter = 0;
94}

Referenced by G4MTRunManager::WaitForEndEventLoopWorkers(), and G4MTRunManager::WaitForReadyWorkers().

◆ SetActiveThreads()

void G4MTBarrier::SetActiveThreads ( unsigned int val)
inline

Definition at line 140 of file G4MTBarrier.hh.

140{ m_numActiveThreads = val; }

Referenced by G4MTRunManager::RequestWorkersProcessCommandsStack(), and Wait().

◆ ThisWorkerReady()

void G4MTBarrier::ThisWorkerReady ( )

Definition at line 40 of file G4MTBarrier.cc.

41{
42 // Step-1: Worker acquires lock on shared resource (the counter)
43 G4AutoLock lock(&m_mutex);
44 // Step-2: Worker increases counter
45 ++m_counter;
46 // Step-3: Worker broadcasts that the counter has changed
47 G4CONDITIONBROADCAST(&m_counterChanged);
48 // Step-4: Worker waits on condition to continue
49 G4CONDITIONWAIT(&m_continue, &lock);
50}
#define G4CONDITIONWAIT(cond, mutex)

Referenced by G4MTRunManager::ThisWorkerEndEventLoop(), G4MTRunManager::ThisWorkerProcessCommandsStackDone(), G4MTRunManager::ThisWorkerReady(), and G4MTRunManager::ThisWorkerWaitForNextAction().

◆ Wait() [1/2]

void G4MTBarrier::Wait ( )

Definition at line 53 of file G4MTBarrier.cc.

54{
55 while(true)
56 {
57 // Step-2: Acquires lock on shared resource (the counter)
58 G4AutoLock lock(&m_mutex);
59 // If the counter equals active threads, all threads are ready, exit the
60 // loop
61 if(m_counter == m_numActiveThreads)
62 {
63 break;
64 }
65 // Step-3: Not all workers are ready, wait for the number to change
66 // before repeating the check
67 G4CONDITIONWAIT(&m_counterChanged, &lock);
68 }
69}

Referenced by G4MTRunManager::NewActionRequest(), Wait(), G4MTRunManager::WaitForEndEventLoopWorkers(), WaitForReadyWorkers(), and G4MTRunManager::WaitForReadyWorkers().

◆ Wait() [2/2]

void G4MTBarrier::Wait ( unsigned int numt)
inline

Definition at line 145 of file G4MTBarrier.hh.

146 {
147 SetActiveThreads(numt);
148 Wait();
149 }
void SetActiveThreads(unsigned int val)

◆ WaitForReadyWorkers()

void G4MTBarrier::WaitForReadyWorkers ( )
virtual

Definition at line 81 of file G4MTBarrier.cc.

82{
83 // Step-1: Master enters a loop to wait all workers to be ready
84 Wait();
85 // Done, all workers are ready, broadcast a continue signal
87}
void ReleaseBarrier()

Referenced by G4MTRunManager::RequestWorkersProcessCommandsStack().


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