1 /*---------------------------------------------------------------------------*\
5 * Copyright (C) 2000-2003 by the OpenSG Forum *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
15 * This library is free software; you can redistribute it and/or modify it *
16 * under the terms of the GNU Library General Public License as published *
17 * by the Free Software Foundation, version 2. *
19 * This library is distributed in the hope that it will be useful, but *
20 * WITHOUT ANY WARRANTY; without even the implied warranty of *
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
22 * Library General Public License for more details. *
24 * You should have received a copy of the GNU Library General Public *
25 * License along with this library; if not, write to the Free Software *
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
37 \*---------------------------------------------------------------------------*/
39 #ifndef _OSGTHREADMANAGER_H_
40 #define _OSGTHREADMANAGER_H_
45 #include "OSGBaseFunctions.h"
48 #if defined(OSG_USE_SPROC)
54 #include "OSGBaseThread.h"
55 #include "OSGBarrier.h"
56 #include "OSGCondVar.h"
58 #include "OSGSemaphore.h"
62 //---------------------------------------------------------------------------
64 //---------------------------------------------------------------------------
66 /*! \ingroup GrpBaseMultiThreading
67 \ingroup GrpLibOSGBase
71 template <class MPFieldT
>
74 /*========================== PUBLIC =================================*/
78 typedef typename
MPFieldT::Type MPFieldType
;
80 /*---------------------------------------------------------------------*/
81 /*! \name Constructor */
87 /*---------------------------------------------------------------------*/
88 /*! \name Destructor */
91 virtual ~MPFieldStore(void);
94 /*---------------------------------------------------------------------*/
98 MPFieldT
*getMPField (const Char8
*szName
,
99 const Char8
*szTypeName
,
102 MPFieldT
*findMPField (const Char8
*szName
);
104 void removeMPField( MPFieldT
*pField
);
107 /*---------------------------------------------------------------------*/
114 /*---------------------------------------------------------------------*/
118 MPFieldType
*findMPFieldType(const Char8
*szName
) const;
121 /*========================= PROTECTED ===============================*/
125 /*---------------------------------------------------------------------*/
129 typedef std::map
<std::string
, MPFieldType
*> MPFieldTypeMap
;
130 typedef typename
MPFieldTypeMap::iterator MPFieldTypeMapIt
;
132 typedef typename
MPFieldTypeMap::const_iterator MPFieldTypeMapCIt
;
134 typedef std::map
<std::string
, MPFieldT
*> MPFieldMap
;
135 typedef typename
MPFieldMap::iterator MPFieldMapIt
;
137 typedef typename
MPFieldMap::const_iterator MPFieldMapCIt
;
140 /*---------------------------------------------------------------------*/
142 MPFieldTypeMap _mFieldTypeMap
;
143 MPFieldMap _mFieldMap
;
145 UInt32
registerMPType(MPFieldType
*pType
);
147 /*========================== PRIVATE ================================*/
151 friend class ThreadManager
;
153 /*!\brief prohibit default function (move to 'public' if needed) */
154 MPFieldStore (const MPFieldStore
&source
);
155 /*!\brief prohibit default function (move to 'public' if needed) */
156 void operator =(const MPFieldStore
&source
);
162 //---------------------------------------------------------------------------
164 //---------------------------------------------------------------------------
166 /*! \ingroup GrpBaseMultiThreading
167 \ingroup GrpLibOSGBase
171 class OSG_BASE_DLLMAPPING ThreadManager
173 /*========================== PUBLIC =================================*/
177 /*---------------------------------------------------------------------*/
181 typedef MPFieldStore
<BaseThread
> ThreadStore
;
182 typedef MPFieldStore
<Barrier
> BarrierStore
;
183 typedef MPFieldStore
<CondVar
> CondVarStore
;
184 typedef MPFieldStore
<Lock
> LockStore
;
185 typedef MPFieldStore
<LockPool
> LockPoolStore
;
186 typedef MPFieldStore
<Semaphore
> SemaphoreStore
;
189 /*---------------------------------------------------------------------*/
190 /*! \name Set / Get */
193 static void setAppThreadType(const Char8
*szAppThreadType
);
195 static ThreadManager
*the ( void );
197 static BaseThread
*getAppThread ( void );
200 /*---------------------------------------------------------------------*/
201 /*! \name Create Threading Element */
204 // bGlobal is passed as UInt32 because Char8 * gets autoconverted to
205 // bool and that would allow existing code to silently compile
207 BaseThreadTransitPtr
getThread (const Char8
*szName
,
209 const Char8
*szTypeName
= "OSGThread");
210 BarrierTransitPtr
getBarrier (const Char8
*szName
,
212 const Char8
*szTypeName
= "OSGBarrier");
213 CondVarTransitPtr
getCondVar (const Char8
*szName
,
215 const Char8
*szTypeName
= "OSGCondVar");
216 LockTransitPtr
getLock (const Char8
*szName
,
218 const Char8
*szTypeName
= "OSGLock");
219 LockPoolTransitPtr
getLockPool (const Char8
*szName
,
221 const Char8
*szTypeName
= "OSGLockPool");
222 SemaphoreTransitPtr
getSemaphore (const Char8
*szName
,
224 const Char8
*szTypeName
="OSGSemaphore");
227 /*---------------------------------------------------------------------*/
231 BaseThread
*findThread (const Char8
*szName
);
232 Barrier
*findBarrier (const Char8
*szName
);
233 CondVar
*findCondVar (const Char8
*szName
);
234 Lock
*findLock (const Char8
*szName
);
235 LockPool
*findLockPool (const Char8
*szName
);
236 Semaphore
*findSemaphore(const Char8
*szName
);
239 /*---------------------------------------------------------------------*/
243 void remove(BaseThread
*pThread
);
244 void remove(Barrier
*pBarrier
);
245 void remove(CondVar
*pCondVar
);
246 void remove(Lock
*pLock
);
247 void remove(LockPool
*pLockPool
);
248 void remove(Semaphore
*pSemaphore
);
251 /*---------------------------------------------------------------------*/
257 #if defined(OSG_USE_SPROC)
259 /*---------------------------------------------------------------------*/
260 /*! \name Set / Get */
263 usptr_t
*getArena(void);
267 /*========================= PROTECTED ===============================*/
271 static bool initialize (void ) ;
272 static bool terminate (void );
274 UInt32
registerThreadType (MPThreadType
*pType
);
275 UInt32
registerBarrierType (MPBarrierType
*pType
);
276 UInt32
registerCondVarType (MPCondVarType
*pType
);
277 UInt32
registerLockType (MPLockType
*pType
);
278 UInt32
registerLockPoolType (MPLockPoolType
*pType
);
279 UInt32
registerSemaphoreType(MPSemaphoreType
*pType
);
282 bool shutdown (void );
284 /*---------------------------------------------------------------------*/
285 /*! \name Constructors */
291 /*---------------------------------------------------------------------*/
292 /*! \name Destructor */
295 virtual ~ThreadManager(void);
298 /*---------------------------------------------------------------------*/
299 /*! \name Destructor */
303 /*========================== PRIVATE ================================*/
307 /*---------------------------------------------------------------------*/
308 /*! \name Friend Classes */
311 friend class MPThreadType
;
312 friend class MPBarrierType
;
313 friend class MPCondVarType
;
314 friend class MPLockType
;
315 friend class MPLockPoolType
;
316 friend class MPSemaphoreType
;
318 friend class BaseThread
;
319 friend class Barrier
;
320 friend class CondVar
;
322 friend class LockPool
;
323 friend class Semaphore
;
325 friend OSG_BASE_DLLMAPPING
bool osgDoInit(Int32 argc
,
333 friend OSG_BASE_DLLMAPPING
bool osgExit (void );
336 /*---------------------------------------------------------------------*/
337 /*! \name Class Variable */
340 static ThreadManager
*_pThreadManager
;
341 static BaseThreadRefPtr _pAppThread
;
343 static bool _bShutdownInProgress
;
346 /*---------------------------------------------------------------------*/
347 /*! \name Instance Variables */
350 ThreadStore _sThreadStore
;
351 BarrierStore _sBarrierStore
;
352 CondVarStore _sCondVarStore
;
353 LockStore _sLockStore
;
354 LockPoolStore _sLockPoolStore
;
355 SemaphoreStore _sSemaphoreStore
;
359 static Char8
*_szAppThreadType
;
361 #if defined(OSG_USE_SPROC)
366 /*---------------------------------------------------------------------*/
368 /*!\brief prohibit default function (move to 'public' if needed) */
369 ThreadManager (const ThreadManager
&source
);
370 /*!\brief prohibit default function (move to 'public' if needed) */
371 void operator =(const ThreadManager
&source
);
376 #include "OSGThreadManager.inl"
378 #endif /* _OSGTHREADMANAGER_H_ */