Import Geant4 10.7.0.beta source tree

This commit is contained in:
Gabriele Cosmo
2020-06-26 10:23:25 +02:00
parent c02c370437
commit 67ba86d073
1871 changed files with 174422 additions and 131884 deletions
+45 -34
View File
@@ -22,69 +22,80 @@
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// G4MTBarrier class implementation
//
// ---------------------------------------------------------------
/*
* G4MTBarrier.cc
*
* Created on: Feb 10, 2016
* Author: adotti
* Updated on: Feb 9, 2018
* Author: jmadsen
*/
// Author: A.Dotti (SLAC), 10 February 2016
// Revision: J.Madsen (NERSC), 09 February 2018
// --------------------------------------------------------------------
#include "G4MTBarrier.hh"
#include "G4AutoLock.hh"
G4MTBarrier::G4MTBarrier(unsigned int numThreads ) :
m_numActiveThreads(numThreads),
m_counter(0)
// --------------------------------------------------------------------
G4MTBarrier::G4MTBarrier(unsigned int numThreads)
: m_numActiveThreads(numThreads)
{}
void G4MTBarrier::ThisWorkerReady() {
//Step-1: Worker acquires lock on shared resource (the counter)
// --------------------------------------------------------------------
void G4MTBarrier::ThisWorkerReady()
{
// Step-1: Worker acquires lock on shared resource (the counter)
G4AutoLock lock(&m_mutex);
//Step-2: Worker increases counter
// Step-2: Worker increases counter
++m_counter;
//Step-3: Worker broadcasts that the counter has changed
// Step-3: Worker broadcasts that the counter has changed
G4CONDITIONBROADCAST(&m_counterChanged);
//Step-4: Worker waits on condition to continue
G4CONDITIONWAIT(&m_continue,&lock);
// Step-4: Worker waits on condition to continue
G4CONDITIONWAIT(&m_continue, &lock);
}
void G4MTBarrier::Wait() {
while (true)
// --------------------------------------------------------------------
void G4MTBarrier::Wait()
{
while(true)
{
//Step-2: Acquires lock on shared resource (the counter)
G4AutoLock lock(&m_mutex);
//If the counter equals active threads, all threads are ready, exit the loop
if ( m_counter == m_numActiveThreads ) { break; }
//Step-3: Not all workers are ready, wait for the number to change
//before repeating the check
G4CONDITIONWAIT(&m_counterChanged,&lock);
// Step-2: Acquires lock on shared resource (the counter)
G4AutoLock lock(&m_mutex);
// If the counter equals active threads, all threads are ready, exit the
// loop
if(m_counter == m_numActiveThreads)
{
break;
}
// Step-3: Not all workers are ready, wait for the number to change
// before repeating the check
G4CONDITIONWAIT(&m_counterChanged, &lock);
}
}
void G4MTBarrier::ReleaseBarrier() {
//Step-4: re-aquire lock and re-set shared resource for future re-use
// --------------------------------------------------------------------
void G4MTBarrier::ReleaseBarrier()
{
// Step-4: re-aquire lock and re-set shared resource for future re-use
G4AutoLock lock(&m_mutex);
m_counter = 0;
G4CONDITIONBROADCAST(&m_continue);
}
void G4MTBarrier::WaitForReadyWorkers() {
//Step-1: Master enters a loop to wait all workers to be ready
// --------------------------------------------------------------------
void G4MTBarrier::WaitForReadyWorkers()
{
// Step-1: Master enters a loop to wait all workers to be ready
Wait();
//Done, all workers are ready, broadcast a continue signal
// Done, all workers are ready, broadcast a continue signal
ReleaseBarrier();
}
void G4MTBarrier::ResetCounter() {
// --------------------------------------------------------------------
void G4MTBarrier::ResetCounter()
{
G4AutoLock l(&m_mutex);
m_counter = 0;
}
unsigned int G4MTBarrier::GetCounter() {
// --------------------------------------------------------------------
unsigned int G4MTBarrier::GetCounter()
{
G4AutoLock l(&m_mutex);
const unsigned int result = m_counter;
return result;