Geant4  10.03.p01
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 // $Id: G4GeometryWorkspacePool.cc 79096 2014-02-14 16:07:39Z gcosmo $
28 //
29 //
30 // Class G4GeometryWorkspacePool - implementation
31 //
32 // ----------------------------------------------------------------------
33 
35 #include "G4GeometryWorkspace.hh"
36 
37 #include "G4AutoLock.hh"
38 
39 namespace
40 {
41  G4Mutex singletonM = G4MUTEX_INITIALIZER;
42 }
43 
44 G4ThreadLocal G4GeometryWorkspace* G4GeometryWorkspacePool::fMyWorkspace=0;
45 
46 G4GeometryWorkspacePool* G4GeometryWorkspacePool::thePool=0;
47 
48 // ----------------------------------------------------------------------
49 //
51 {
52  G4AutoLock l(&singletonM);
53  if ( !thePool ) { thePool= new G4GeometryWorkspacePool(); }
54  return thePool;
55 }
56 
57 // ----------------------------------------------------------------------
58 // For use with MT and current G4WorkerThread -- which uses static methods
59 //
61 {
62  G4GeometryWorkspace* geometryWrk=0;
63  if( !fMyWorkspace )
64  {
65  geometryWrk= new G4GeometryWorkspace();
66 
67  if( !geometryWrk )
68  {
69  G4Exception("GeometryWorspacePool::CreateWorkspace", "GeomVol003",
70  FatalException, "Failed to create workspace.");
71  }
72  else
73  {
74  fMyWorkspace= geometryWrk;
75  }
76  }
77  else
78  {
79  G4Exception("GeometryWorspacePool::CreateWorkspace", "GeomVol003",
81  "Cannot create workspace twice for the same thread.");
82  geometryWrk= fMyWorkspace;
83  }
84 
85  return geometryWrk;
86 }
87 
88 // ----------------------------------------------------------------------
89 // Create it (as above) and use it
90 //
92 {
93  (this->CreateWorkspace())->UseWorkspace();
94 }
95 
96 // ----------------------------------------------------------------------
97 // Reuse an existing workspace - or create a new one if needed.
98 //
100 {
101  G4GeometryWorkspace* geometryWrk= fMyWorkspace;
102  if( !geometryWrk )
103  {
104  geometryWrk= this->CreateWorkspace();
105  }
106  geometryWrk->UseWorkspace();
107 
108  fMyWorkspace= geometryWrk; // assign it for use by this thread.
109  return geometryWrk;
110 }
111 
112 // ----------------------------------------------------------------------
113 //
115 {
116  geometryWrk->ReleaseWorkspace();
117  // if( fWarehouse ){
118  // } else {
119  delete geometryWrk;
120  // }
121 }
122 
123 // ----------------------------------------------------------------------
124 //
126 {
127 }
128 
129 // ----------------------------------------------------------------------
130 //
131 G4GeometryWorkspacePool::G4GeometryWorkspacePool()
132 {
133  // fWarehouse=0;
134 }
135 
136 // ----------------------------------------------------------------------
137 //
138 G4GeometryWorkspacePool::~G4GeometryWorkspacePool()
139 {
140 }
#define G4ThreadLocal
Definition: tls.hh:89
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:175
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:173
static G4GeometryWorkspacePool * GetInstance()
void Recycle(G4GeometryWorkspace *)