Import Geant4 11.3.0 source tree

This commit is contained in:
Gabriele Cosmo
2024-12-06 11:11:40 +01:00
parent e58e650b32
commit 32390e802b
1984 changed files with 98713 additions and 83996 deletions
@@ -6,6 +6,10 @@ It must **not** be used as a substitute for writing good git commit messages!
-------------------------------------------------------------------------------
## 2024-11-04 Vladimir Ivantchenko (phys-ctor-fact-V11-02-01)
- G4PhysicsConstructorRegistry - removed memory leak at exit by using of
G4ThreadLocalSingleton pattern
## 2024-05-15 Gabriele Cosmo (phys-ctor-fact-V11-02-00)
- Minor code cleanup in G4PhysicsConstructorRegistry source.
@@ -48,13 +48,16 @@
#include <vector>
#include <map>
#include "globals.hh"
#include "G4ThreadLocalSingleton.hh"
class G4VPhysicsConstructor;
class G4VBasePhysConstrFactory;
class G4PhysicsConstructorRegistry
{
friend class G4ThreadLocalSingleton<G4PhysicsConstructorRegistry>;
public:
static G4PhysicsConstructorRegistry* Instance();
@@ -87,9 +90,9 @@ private:
static G4ThreadLocal G4PhysicsConstructorRegistry* theInstance;
std::vector <G4VPhysicsConstructor*> physConstr;
std::vector<G4VPhysicsConstructor*> physConstr;
std::map <G4String, G4VBasePhysConstrFactory*> factories;
std::map<G4String, G4VBasePhysConstrFactory*> factories;
};
@@ -47,7 +47,10 @@ G4ThreadLocal G4PhysicsConstructorRegistry* G4PhysicsConstructorRegistry::theIns
G4PhysicsConstructorRegistry* G4PhysicsConstructorRegistry::Instance()
{
if(nullptr == theInstance) theInstance = new G4PhysicsConstructorRegistry;
if (nullptr == theInstance) {
static G4ThreadLocalSingleton<G4PhysicsConstructorRegistry> inst;
theInstance = inst.Instance();
}
return theInstance;
}
@@ -61,41 +64,25 @@ G4PhysicsConstructorRegistry::~G4PhysicsConstructorRegistry()
void G4PhysicsConstructorRegistry::Clean()
{
std::size_t n = physConstr.size();
if(n > 0) {
for (std::size_t i=0; i<n; ++i) {
if(physConstr[i]) {
G4VPhysicsConstructor* p = physConstr[i];
physConstr[i] = nullptr;
delete p;
}
}
physConstr.clear();
}
for (auto const & ptr : physConstr) { delete ptr; }
physConstr.clear();
}
void G4PhysicsConstructorRegistry::Register(G4VPhysicsConstructor* p)
{
if(nullptr == p) return;
std::size_t n = physConstr.size();
if(n > 0) {
for (std::size_t i=0; i<n; ++i) {
if(physConstr[i] == p) { return; }
}
}
if (nullptr == p) { return; }
for (auto const & ptr : physConstr) { if (p == ptr) { return; } }
physConstr.push_back(p);
}
void G4PhysicsConstructorRegistry::DeRegister(G4VPhysicsConstructor* p)
{
if (nullptr == p) return;
if (nullptr == p || physConstr.empty()) { return; }
std::size_t n = physConstr.size();
if ( n > 0 ) {
for (std::size_t i=0; i<n; ++i) {
if ( physConstr[i] == p ) {
physConstr[i] = nullptr;
return;
}
for (std::size_t i=0; i<n; ++i) {
if ( physConstr[i] == p ) {
physConstr[i] = nullptr;
return;
}
}
}