Geant4_10
G4GeometryWorkspacePool.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 
27 #include "G4Types.hh"
28 
30 #include "G4GeometryWorkspace.hh"
31 
32 #include "G4AutoLock.hh"
33 namespace {
34  G4Mutex singletonM = G4MUTEX_INITIALIZER;
35 }
36 G4ThreadLocal G4GeometryWorkspace* G4GeometryWorkspacePool::fMyWorkspace=0;
37 
38 G4GeometryWorkspacePool* G4GeometryWorkspacePool::thePool=0;
39 
41 {
42  G4AutoLock l(&singletonM);
43  if( !thePool ) thePool= new G4GeometryWorkspacePool();
44  return thePool;
45 }
46 
47 // For use with MT and current G4WorkerThread -- which uses static methods
49 {
50  G4GeometryWorkspace* geometryWrk=0;
51  if( !fMyWorkspace ){
52  geometryWrk= new G4GeometryWorkspace();
53 
54  if( !geometryWrk ) {
55  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
56  FatalException, "Failed to create workspace.");
57  }else{
58  fMyWorkspace= geometryWrk;
59  }
60  }else{
61  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
63  "Cannot create workspace twice for the same thread.");
64  geometryWrk= fMyWorkspace;
65  }
66 
67  return geometryWrk;
68 }
69 
70 
71 void G4GeometryWorkspacePool::CreateAndUseWorkspace() // Create it (as above) and use it
72 {
73  (this->CreateWorkspace())->UseWorkspace();
74 }
75 
76 // Reuse an existing workspace - or create a new one if needed.
77 //
79 {
80  G4GeometryWorkspace* geometryWrk= fMyWorkspace;
81  if( !geometryWrk ){
82  geometryWrk= this->CreateWorkspace();
83  }
84  geometryWrk->UseWorkspace();
85 
86  fMyWorkspace= geometryWrk; // assign it for use by this thread.
87  return geometryWrk;
88 }
89 
90 #if 0
91 void G4GeometryWorkspacePool::ReleaseAndDestroyMyWorkspace()
92 {
93  ReleaseAndDestroyWorkspace(fMyWorkspace);
94  fMyWorkspace=0;
95 }
96 
98 {
99  geometryWrk->ReleaseWorkspace();
100  delete geometryWrk;
101 }
102 #endif
103 
105 {
106  geometryWrk->ReleaseWorkspace();
107  //if( fWarehouse ){
108  //} else {
109  delete geometryWrk;
110  //}
111 }
112 
114 {
115 }
116 
117 
118 G4GeometryWorkspacePool::G4GeometryWorkspacePool()
119 {
120  // fWarehouse=0;
121 }
122 
123 G4GeometryWorkspacePool::~G4GeometryWorkspacePool()
124 {
125 }
126 
127 
128 
#define G4ThreadLocal
Definition: tls.hh:52
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:158
void ReleaseAndDestroyWorkspace(G4GeometryWorkspace *)
G4GeometryWorkspace * FindOrCreateWorkspace()
G4GeometryWorkspace * CreateWorkspace()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int G4Mutex
Definition: G4Threading.hh:156
static G4GeometryWorkspacePool * GetInstance()
void Recycle(G4GeometryWorkspace *)