fixed: auto_ptr -> unique_ptr
[opensg.git] / Source / Base / Threading / OSGMPBase.cpp
blob82cb38d06abc160376920823805fa71346d02297
1 /*---------------------------------------------------------------------------*\
2 * OpenSG *
3 * *
4 * *
5 * Copyright (C) 2000-2003 by the OpenSG Forum *
6 * *
7 * www.opensg.org *
8 * *
9 * contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de *
10 * *
11 \*---------------------------------------------------------------------------*/
12 /*---------------------------------------------------------------------------*\
13 * License *
14 * *
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. *
18 * *
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. *
23 * *
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. *
27 * *
28 \*---------------------------------------------------------------------------*/
29 /*---------------------------------------------------------------------------*\
30 * Changes *
31 * *
32 * *
33 * *
34 * *
35 * *
36 * *
37 \*---------------------------------------------------------------------------*/
39 #include <cstdlib>
40 #include <cstdio>
42 #include "OSGConfig.h"
44 #include <iostream>
46 #include "OSGMPBase.h"
47 #include "OSGTypeFactory.h"
48 #include "OSGBaseFunctions.h"
49 #include "OSGThreadManager.h"
51 OSG_USING_NAMESPACE
53 //---------------------------------------------------------------------------
54 // Class
55 //---------------------------------------------------------------------------
57 /*! \class OSG::MPType
60 MPType::MPType(const Char8 *szName,
61 const Char8 *szParentName,
62 const UInt32 uiNamespace ) :
63 Inherited(szName,
64 szParentName,
65 uiNamespace )
70 MPType::~MPType(void)
77 //---------------------------------------------------------------------------
78 // Class
79 //---------------------------------------------------------------------------
81 /*! \class OSG::MPThreadType
84 UInt32 MPThreadType::_uiThreadCount = 0;
87 MPThreadType::MPThreadType(const Char8 *szName,
88 const Char8 *szParentName,
89 CreateThreadF fCreateThread,
90 InitThreadingF fInitThreading,
91 const UInt32 uiNamespace ) :
92 Inherited (szName, szParentName, uiNamespace),
93 _fCreateThread(fCreateThread )
95 ThreadManager::the()->registerThreadType(this);
97 if(fInitThreading != NULL)
98 fInitThreading();
102 MPThreadType::~MPThreadType(void)
107 BaseThread *MPThreadType::create(const Char8 *szName, bool bGlobal)
109 Char8 *szTmp;
110 UInt32 uiNewId = _uiThreadCount++;
111 BaseThread *returnValue = NULL;
113 if(szName == NULL)
115 szTmp = new Char8[32];
116 sprintf(szTmp, "OSGThread_%u", uiNewId);
118 else
120 szTmp = const_cast<Char8 *>(szName);
123 if(_fCreateThread != NULL)
124 returnValue = _fCreateThread(szTmp, uiNewId, bGlobal);
126 if(szTmp != szName)
127 delete [] szTmp;
129 return returnValue;
133 //---------------------------------------------------------------------------
134 // Class
135 //---------------------------------------------------------------------------
137 /*! \class OSG::MPCondVarType
140 UInt32 MPCondVarType::_uiCondVarCount = 0;
143 MPCondVarType::MPCondVarType(const Char8 *szName,
144 const Char8 *szParentName,
145 CreateCondVarF fCreateCondVar,
146 const UInt32 uiNamespace ) :
147 Inherited (szName, szParentName, uiNamespace),
148 _fCreateCondVar(fCreateCondVar )
150 ThreadManager::the()->registerCondVarType(this);
154 MPCondVarType::~MPCondVarType(void)
159 CondVar *MPCondVarType::create(const Char8 *szName, bool bGlobal)
161 Char8 *szTmp;
162 UInt32 uiNewId = _uiCondVarCount++;
163 CondVar *returnValue = NULL;
165 if(szName == NULL)
167 szTmp = new Char8[32];
168 sprintf(szTmp, "OSGCondVar_%u", uiNewId);
170 else
172 szTmp = const_cast<Char8 *>(szName);
175 if(_fCreateCondVar != NULL)
176 returnValue = _fCreateCondVar(szTmp, uiNewId, bGlobal);
178 if(szTmp != szName)
179 delete [] szTmp;
181 return returnValue;
186 //---------------------------------------------------------------------------
187 // Class
188 //---------------------------------------------------------------------------
190 /*! \class OSG::MPBarrierType
193 UInt32 MPBarrierType::_uiBarrierCount = 0;
196 MPBarrierType::MPBarrierType(const Char8 *szName,
197 const Char8 *szParentName,
198 CreateBarrierF fCreateBarrier,
199 const UInt32 uiNamespace ) :
200 Inherited (szName, szParentName, uiNamespace),
201 _fCreateBarrier(fCreateBarrier )
203 ThreadManager::the()->registerBarrierType(this);
207 MPBarrierType::~MPBarrierType(void)
212 Barrier *MPBarrierType::create(const Char8 *szName, bool bGlobal)
214 Char8 *szTmp;
215 UInt32 uiNewId = _uiBarrierCount++;
216 Barrier *returnValue = NULL;
218 if(szName == NULL)
220 szTmp = new Char8[32];
221 sprintf(szTmp, "OSGBarrier_%u", uiNewId);
223 else
225 szTmp = const_cast<Char8 *>(szName);
228 if(_fCreateBarrier != NULL)
229 returnValue = _fCreateBarrier(szTmp, uiNewId, bGlobal);
231 if(szTmp != szName)
232 delete [] szTmp;
234 return returnValue;
240 //---------------------------------------------------------------------------
241 // Class
242 //---------------------------------------------------------------------------
244 /*! \class OSG::MPLockType
247 UInt32 MPLockType::_uiLockCount = 0;
250 MPLockType::MPLockType(const Char8 *szName,
251 const Char8 *szParentName,
252 CreateLockF fCreateLock,
253 const UInt32 uiNamespace ) :
254 Inherited (szName, szParentName, uiNamespace),
255 _fCreateLock(fCreateLock )
257 ThreadManager::the()->registerLockType(this);
261 MPLockType::~MPLockType(void)
266 Lock *MPLockType::create(const Char8 *szName, bool bGlobal)
268 Char8 *szTmp;
269 UInt32 uiNewId = _uiLockCount++;
270 Lock *returnValue = NULL;
272 if(szName == NULL)
274 szTmp = new Char8[32];
275 sprintf(szTmp, "OSGLock_%u", uiNewId);
277 else
279 szTmp = const_cast<Char8 *>(szName);
282 if(_fCreateLock != NULL)
283 returnValue = _fCreateLock(szTmp, uiNewId, bGlobal);
285 if(szTmp != szName)
286 delete [] szTmp;
288 return returnValue;
294 //---------------------------------------------------------------------------
295 // Class
296 //---------------------------------------------------------------------------
298 /*! \class OSG::MPLockPoolType
301 UInt32 MPLockPoolType::_uiLockPoolCount = 0;
304 MPLockPoolType::MPLockPoolType(
305 const Char8 *szName,
306 const Char8 *szParentName,
307 CreateLockPoolF fCreateLockPool,
308 const UInt32 uiNamespace ) :
310 Inherited (szName, szParentName, uiNamespace),
311 _fCreateLockPool(fCreateLockPool )
313 ThreadManager::the()->registerLockPoolType(this);
317 MPLockPoolType::~MPLockPoolType(void)
322 LockPool *MPLockPoolType::create(const Char8 *szName, bool bGlobal)
324 Char8 *szTmp;
325 UInt32 uiNewId = _uiLockPoolCount++;
326 LockPool *returnValue = NULL;
328 if(szName == NULL)
330 szTmp = new Char8[32];
331 sprintf(szTmp, "OSGThread_%u", uiNewId);
333 else
335 szTmp = const_cast<Char8 *>(szName);
338 if(_fCreateLockPool != NULL)
339 returnValue = _fCreateLockPool(szTmp, uiNewId, bGlobal);
341 if(szTmp != szName)
342 delete [] szTmp;
344 return returnValue;
349 //---------------------------------------------------------------------------
350 // Class
351 //---------------------------------------------------------------------------
353 /*! \class OSG::MPSemaphoreType
356 UInt32 MPSemaphoreType::_uiSemaphoreCount = 0;
359 MPSemaphoreType::MPSemaphoreType(const Char8 *szName,
360 const Char8 *szParentName,
361 CreateSemaphoreF fCreateSemaphore,
362 const UInt32 uiNamespace ) :
363 Inherited (szName, szParentName, uiNamespace),
364 _fCreateSemaphore(fCreateSemaphore )
366 ThreadManager::the()->registerSemaphoreType(this);
370 MPSemaphoreType::~MPSemaphoreType(void)
375 Semaphore *MPSemaphoreType::create(const Char8 *szName, bool bGlobal)
377 Char8 *szTmp;
378 UInt32 uiNewId = _uiSemaphoreCount++;
379 Semaphore *returnValue = NULL;
381 if(szName == NULL)
383 szTmp = new Char8[32];
384 sprintf(szTmp, "OSGSemaphore_%u", uiNewId);
386 else
388 szTmp = const_cast<Char8 *>(szName);
391 if(_fCreateSemaphore != NULL)
392 returnValue = _fCreateSemaphore(szTmp, uiNewId, bGlobal);
394 if(szTmp != szName)
395 delete [] szTmp;
397 return returnValue;
401 //---------------------------------------------------------------------------
402 // Class
403 //---------------------------------------------------------------------------
405 /*! \class OSG::MPBase
408 MPType MPBase::_type("OSGMPBase", NULL);
411 const MPType &MPBase::getStaticType(void)
413 return _type;
417 UInt32 MPBase::getStaticTypeId(void)
419 return 0;
423 MPType &MPBase::getType(void)
425 return _type;
429 const MPType &MPBase::getType(void) const
431 return _type;
435 UInt32 MPBase::getTypeId(void)
437 return getType().getId();
441 const Char8 *MPBase::getCName(void) const
443 return _szName;
447 MPBase::MPBase(const Char8 *szName, bool bGlobal) :
448 Inherited( ),
450 _szName (NULL ),
451 _bGlobal (bGlobal)
453 osgStringDup(szName, _szName);
457 MPBase::~MPBase(void)
459 delete [] _szName;