From 4ab8b9b72d8d86c5d1745f43500a052a1bfffeed Mon Sep 17 00:00:00 2001 From: scott snyder <sss@karma> Date: Fri, 16 Oct 2020 09:43:29 -0400 Subject: [PATCH] LArG4Code: Enable thread-safety checking. Enable thread-safety checking. Fix resulting warnings. --- .../LArG4Code/LArG4Code/ATLAS_CHECK_THREAD_SAFETY | 1 + .../LArG4/LArG4Code/LArG4Code/CalibrationHit.h | 4 ++-- .../LArG4Code/DerivedILArCalculatorSvcForTest.h | 10 +++++----- .../LArG4Code/DerivedILArCalibCalculatorSvcForTest.h | 10 +++++----- LArCalorimeter/LArG4/LArG4Code/src/CalibrationHit.cc | 4 ++-- LArCalorimeter/LArG4/LArG4Code/src/LArG4Identifier.cc | 10 +++------- .../LArG4/LArG4Code/test/LArG4CalibSD_gtest.cxx | 3 +++ .../LArG4/LArG4Code/test/LArG4SimpleSD_gtest.cxx | 3 +++ .../LArG4/LArG4Code/test/SDWrapper_gtest.cxx | 5 ++++- 9 files changed, 28 insertions(+), 22 deletions(-) create mode 100644 LArCalorimeter/LArG4/LArG4Code/LArG4Code/ATLAS_CHECK_THREAD_SAFETY diff --git a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/ATLAS_CHECK_THREAD_SAFETY b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/ATLAS_CHECK_THREAD_SAFETY new file mode 100644 index 00000000000..874f85699a4 --- /dev/null +++ b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/ATLAS_CHECK_THREAD_SAFETY @@ -0,0 +1 @@ +LArCalorimeter/LArG4/LArG4Code diff --git a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/CalibrationHit.h b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/CalibrationHit.h index 316f9403f56..340425b93c3 100644 --- a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/CalibrationHit.h +++ b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/CalibrationHit.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CalibrationHit.h @@ -122,7 +122,7 @@ namespace LArG4 { typedef G4THitsCollection<CalibrationHit> CalibrationHitsCollection; - extern G4Allocator<CalibrationHit> CalibrationHitAllocator; + extern thread_local G4Allocator<CalibrationHit> CalibrationHitAllocator; inline void* CalibrationHit::operator new(size_t) { diff --git a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalculatorSvcForTest.h b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalculatorSvcForTest.h index 24feb99cb11..22f8ab1350f 100644 --- a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalculatorSvcForTest.h +++ b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalculatorSvcForTest.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // defining this class is just used for testing since class ILArCalculatorSvc is a abstract class which needs to be instatiated in my test code @@ -7,8 +7,8 @@ // To make matters more complicated, the classes(i.e. INamedInterface and IStateful) that IService inherits are also abstract, so I need to override the pure virtual functions in classes INamedInterface and IStateful // In addition, since INamedInterface and IStateful all inherit the class IInterface, which is abstract. Therefore, I also override the pure virtual functions in the class IInterface. -#ifndef __DERIVEDILARCALCULATORSVC_H__ -#define __DERIVEDILARCALCULATORSVC_H__ +#ifndef LARG4CODE_DERIVEDILARCALCULATORSVCFORTEST_H +#define LARG4CODE_DERIVEDILARCALCULATORSVCFORTEST_H #include "LArG4Code/ILArCalculatorSvc.h" #include "GaudiKernel/StateMachine.h" @@ -130,9 +130,9 @@ public: return Gaudi::StateMachine::State(0); } - std::string& name() const + const std::string& name() const { - static std::string Tes = "test"; + static const std::string Tes = "test"; return Tes; } diff --git a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalibCalculatorSvcForTest.h b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalibCalculatorSvcForTest.h index f44bf00a455..f3863446395 100644 --- a/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalibCalculatorSvcForTest.h +++ b/LArCalorimeter/LArG4/LArG4Code/LArG4Code/DerivedILArCalibCalculatorSvcForTest.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // defining this class is just used for testing since class LArCalibCalculatorSvc is a abstract class which needs to be instatiated in my test code @@ -7,8 +7,8 @@ // To make matters more complicated, the classes(i.e. INamedInterface and IStateful) that IService inherits are also abstract, so I need to override the pure virtual functions in classes INamedInterface and IStateful // In addition, since INamedInterface and IStateful all inherit the class IInterface, which is abstract. Therefore, I also override the pure virtual functions in the class IInterface. -#ifndef __DERIVEDILARCALIBCALCULATORSVC_H__ -#define __DERIVEDILARCALIBCALCULATORSVC_H__ +#ifndef LARG4CODE_DERIVEDILARCALIBCALCULATORSVCFORTEST_H +#define LARG4CODE_DERIVEDILARCALIBCALCULATORSVCFORTEST_H #include "LArG4Code/ILArCalibCalculatorSvc.h" #include "GaudiKernel/StateMachine.h" @@ -130,9 +130,9 @@ public: return Gaudi::StateMachine::State(0); } - std::string& name() const + const std::string& name() const { - static std::string Tes = "test"; + static const std::string Tes = "test"; return Tes; } diff --git a/LArCalorimeter/LArG4/LArG4Code/src/CalibrationHit.cc b/LArCalorimeter/LArG4/LArG4Code/src/CalibrationHit.cc index 3ea60f5b154..90d001b7bbb 100644 --- a/LArCalorimeter/LArG4/LArG4Code/src/CalibrationHit.cc +++ b/LArCalorimeter/LArG4/LArG4Code/src/CalibrationHit.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ // CalibrationHit.h @@ -16,7 +16,7 @@ namespace LArG4 { - G4Allocator<CalibrationHit> CalibrationHitAllocator; + thread_local G4Allocator<CalibrationHit> CalibrationHitAllocator; void CalibrationHit::Draw() {;} diff --git a/LArCalorimeter/LArG4/LArG4Code/src/LArG4Identifier.cc b/LArCalorimeter/LArG4/LArG4Code/src/LArG4Identifier.cc index 107e3d3c5b5..a959acfaf7b 100644 --- a/LArCalorimeter/LArG4/LArG4Code/src/LArG4Identifier.cc +++ b/LArCalorimeter/LArG4/LArG4Code/src/LArG4Identifier.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ @@ -122,11 +122,7 @@ LArG4Identifier::element_type & LArG4Identifier::operator [] (size_type index) if (index >= m_fields.size ()) { - static element_type dummy = 0; - - set_last_error (field_not_found); - - return (dummy); + throw std::out_of_range ("LArG4Identifier::operator[]"); } return (m_fields[index]); @@ -355,7 +351,7 @@ void LArG4Identifier::show () const //---------------------------------------------------------------- LArG4Identifier::error_code LArG4Identifier::set_last_error (error_code code) const { - static error_code last = none; + static thread_local error_code last = none; if (code != get) { diff --git a/LArCalorimeter/LArG4/LArG4Code/test/LArG4CalibSD_gtest.cxx b/LArCalorimeter/LArG4/LArG4Code/test/LArG4CalibSD_gtest.cxx index 8baa79ded2a..6e2382c17fa 100644 --- a/LArCalorimeter/LArG4/LArG4Code/test/LArG4CalibSD_gtest.cxx +++ b/LArCalorimeter/LArG4/LArG4Code/test/LArG4CalibSD_gtest.cxx @@ -2,6 +2,9 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include "CxxUtils/checker_macros.h" +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; + #include "LArG4Code/LArG4CalibSD.h" #include "gtest/gtest.h" diff --git a/LArCalorimeter/LArG4/LArG4Code/test/LArG4SimpleSD_gtest.cxx b/LArCalorimeter/LArG4/LArG4Code/test/LArG4SimpleSD_gtest.cxx index 2296f3d31e0..08b5ff3201c 100644 --- a/LArCalorimeter/LArG4/LArG4Code/test/LArG4SimpleSD_gtest.cxx +++ b/LArCalorimeter/LArG4/LArG4Code/test/LArG4SimpleSD_gtest.cxx @@ -2,6 +2,9 @@ Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include "CxxUtils/checker_macros.h" +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; + #include "LArG4Code/LArG4SimpleSD.h" #include "gtest/gtest.h" diff --git a/LArCalorimeter/LArG4/LArG4Code/test/SDWrapper_gtest.cxx b/LArCalorimeter/LArG4/LArG4Code/test/SDWrapper_gtest.cxx index 3a4ff99cc71..a1868ca958f 100644 --- a/LArCalorimeter/LArG4/LArG4Code/test/SDWrapper_gtest.cxx +++ b/LArCalorimeter/LArG4/LArG4Code/test/SDWrapper_gtest.cxx @@ -1,7 +1,10 @@ /* - Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration */ +#include "CxxUtils/checker_macros.h" +ATLAS_NO_CHECK_FILE_THREAD_SAFETY; + #define SDWRAPPER_TEST//define the macro name to use it in the tested class SDWrapper. Using the macro name to do conditional compiling on the "private:" statement in the file SDWrapper.h #include "LArG4Code/SDWrapper.h" -- GitLab