Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4SolidsWorkspacePool.cc
이 파일의 문서화 페이지로 가기
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 
34 namespace
35 {
36  G4Mutex singletonMutexSWP = G4MUTEX_INITIALIZER;
37 }
38 
40 {
41  G4ThreadLocalStatic G4SolidsWorkspace* _instance = nullptr;
42  return _instance;
43 }
45 
47 {
48  G4AutoLock l(&singletonMutexSWP);
49  if( !thePool ) { thePool= new G4SolidsWorkspacePool(); }
50  return thePool;
51 }
52 
53 // For use with MT and current G4WorkerThread -- which uses static methods
54 //
56 {
57  G4SolidsWorkspace* geometryWrk=0;
58  if( !fMyWorkspace() )
59  {
60  geometryWrk= new G4SolidsWorkspace();
61 
62  if( !geometryWrk )
63  {
64  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
65  FatalException, "Failed to create workspace.");
66  }
67  else
68  {
69  // geometryWrk->UseWorkspace(); // Do not assign it already.
70  fMyWorkspace()= geometryWrk;
71  }
72  }
73  else
74  {
75  G4Exception("GeometryWorspacePool::CreateWorkspace", "Geom-003",
77  "Cannot create workspace twice for the same thread.");
78  geometryWrk= fMyWorkspace();
79  }
80 
81  return geometryWrk;
82 }
83 
84 // Create it (as above) and use it
85 //
87 {
88  (this->CreateWorkspace())->UseWorkspace();
89 }
90 
91 // Reuse an existing workspace - or create a new one if needed.
92 //
94 {
95  G4SolidsWorkspace* geometryWrk= fMyWorkspace();
96  if( !geometryWrk )
97  {
98  geometryWrk= this->CreateWorkspace();
99  }
100  geometryWrk->UseWorkspace();
101 
102  fMyWorkspace()= geometryWrk; // assign it for use by this thread.
103  return geometryWrk;
104 }
105 
106 
107 // Keep the unused Workspace - for recycling
108 //
110 {
111  geometryWrk->ReleaseWorkspace();
112  delete geometryWrk;
113 }
114 
115 
117 {
118  if (fMyWorkspace())
119  {
121  delete fMyWorkspace();
122  fMyWorkspace()=0;
123  }
124 }
125 
126 
128 {
129 // fWarehouse=0;
130 }
131 
132 
134 {
135 }
static G4SolidsWorkspacePool * thePool
void Recycle(G4SolidsWorkspace *)
static G4SolidsWorkspacePool * GetInstance()
#define G4ThreadLocalStatic
Definition: tls.hh:68
static G4GEOM_DLL G4SolidsWorkspace *& fMyWorkspace()
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:88
G4SolidsWorkspace * CreateWorkspace()
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
G4SolidsWorkspace * FindOrCreateWorkspace()
std::mutex G4Mutex
Definition: G4Threading.hh:84