From 19990582876f2b1237fe60df21d42af705f8c407 Mon Sep 17 00:00:00 2001 From: James Beacham <j.beacham@cern.ch> Date: Fri, 16 Mar 2018 19:27:23 +0000 Subject: [PATCH] Merge branch 'SimulationEnergiesThreadSafetyPt1_21.0' into '21.0' Replace static bool variables with std::call_once (ATLASSIM-3568) See merge request atlas/athena!9651 --- .../CaloG4Sim/src/SimulationEnergies.cc | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc b/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc index 69b04c80883..023d038f849 100644 --- a/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc +++ b/Calorimeter/CaloG4Sim/src/SimulationEnergies.cc @@ -120,7 +120,10 @@ #include "G4TouchableHistory.hh" #include "G4ios.hh" +#include <mutex> +static std::once_flag warning1OnceFlag; +static std::once_flag warning2OnceFlag; namespace CaloG4 { @@ -564,17 +567,13 @@ namespace CaloG4 } // If we get here, the registry was never initialized for LAr. - // FIXME: thread-unsafe statics!!! - static G4bool errorDisplayed = false; - if ( ! errorDisplayed ) { - errorDisplayed = true; - G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl - << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl - << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl - << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl - << " will be recorded." << G4endl; - } - + std::call_once(warning1OnceFlag, [](){ + G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl + << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl + << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl + << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl + << " will be recorded." << G4endl; + }); return false; } else { @@ -588,17 +587,14 @@ namespace CaloG4 } // If we get here, the registry was never initialized for LAr. - // FIXME: thread-unsafe statics!!! - static G4bool errorDisplayed1 = false; - if ( ! errorDisplayed1 ) { - errorDisplayed1 = true; - G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl - <<" WARNING! touchableHandle->GetVolume()==0 geometry problem ? and also" << G4endl - << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl - << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl - << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl - << " will be recorded." << G4endl; - } + std::call_once(warning2OnceFlag, [](){ + G4cout << "SimulationEnergies::ProcessEscapedEnergy - " << G4endl + <<" WARNING! touchableHandle->GetVolume()==0 geometry problem ? and also" << G4endl + << " WARNING! CaloG4::EscapedEnergyRegistry was never initialized for 'LArG4::'" << G4endl + << " and LArG4Sim is the package with the code that handles CalibrationHits" << G4endl + << " in non-sensitive volumes. Not all energies deposited in this simulation" << G4endl + << " will be recorded." << G4endl; + }); return false; } } -- GitLab