Geant4  10.01.p02
G4SolidsWorkspacePool.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 
29 #include "G4SolidsWorkspacePool.hh"
30 #include "G4SolidsWorkspace.hh"
31 
32 #include "G4AutoLock.hh"
33 namespace {
34  G4Mutex singletonMutexSWP = G4MUTEX_INITIALIZER;
35 }
36 
38 
40 
41 // static
43 {
44  G4AutoLock l(&singletonMutexSWP);
46  return thePool;
47 }
48 
49 // For use with MT and current G4WorkerThread -- which uses static methods
51 {
52  G4SolidsWorkspace* geometryWrk=0;
53  if( !fMyWorkspace ){
54  geometryWrk= new G4SolidsWorkspace();
55 
56  if( !geometryWrk ) {
57  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
58  FatalException, "Failed to create workspace.");
59  }else{
60  // geometryWrk->UseWorkspace(); // Do not assign it already.
61  fMyWorkspace= geometryWrk;
62  }
63  }else{
64  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
66  "Cannot create workspace twice for the same thread.");
67  geometryWrk= fMyWorkspace;
68  }
69 
70  return geometryWrk;
71 }
72 
73 
74 void G4SolidsWorkspacePool::CreateAndUseWorkspace() // Create it (as above) and use it
75 {
76  (this->CreateWorkspace())->UseWorkspace();
77 }
78 
79 // Reuse an existing workspace - or create a new one if needed.
80 //
82 {
83  G4SolidsWorkspace* geometryWrk= fMyWorkspace;
84  if( !geometryWrk ){
85  geometryWrk= this->CreateWorkspace();
86  }
87  geometryWrk->UseWorkspace();
88 
89  fMyWorkspace= geometryWrk; // assign it for use by this thread.
90  return geometryWrk;
91 }
92 
93 #if 0
94 void G4SolidsWorkspacePool::ReleaseAndDestroyMyWorkspace()
95 {
97  fMyWorkspace=0;
98 }
99 
101 {
102  geometryWrk->ReleaseWorkspace();
103  delete geometryWrk;
104 }
105 #endif
106 
108 {
109  geometryWrk->ReleaseWorkspace();
110 // if( fWarehouse ){
111 // } else {
112  delete geometryWrk;
113 // }
114 }
115  // Keep the unused Workspace - for recycling
116 
117 
119 {
120 }
121 
122 
124 {
125 // fWarehouse=0;
126 }
127 
129 {
130 }
131 
132 
133 
static G4ThreadLocal G4SolidsWorkspace * fMyWorkspace
G4SolidsWorkspace * FindOrCreateWorkspace()
static G4SolidsWorkspacePool * GetInstance()
#define G4ThreadLocal
Definition: tls.hh:89
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
static G4SolidsWorkspacePool * thePool
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int G4Mutex
Definition: G4Threading.hh:173
void Recycle(G4SolidsWorkspace *)
G4SolidsWorkspace * CreateWorkspace()
void ReleaseAndDestroyWorkspace(G4SolidsWorkspace *)