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 \*---------------------------------------------------------------------------*/
42 #include "OSGConfig.h"
46 #include "OSGMPBase.h"
47 #include "OSGTypeFactory.h"
48 #include "OSGBaseFunctions.h"
49 #include "OSGThreadManager.h"
53 //---------------------------------------------------------------------------
55 //---------------------------------------------------------------------------
57 /*! \class OSG::MPType
60 MPType::MPType(const Char8
*szName
,
61 const Char8
*szParentName
,
62 const UInt32 uiNamespace
) :
77 //---------------------------------------------------------------------------
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
)
102 MPThreadType::~MPThreadType(void)
107 BaseThread
*MPThreadType::create(const Char8
*szName
, bool bGlobal
)
110 UInt32 uiNewId
= _uiThreadCount
++;
111 BaseThread
*returnValue
= NULL
;
115 szTmp
= new Char8
[32];
116 sprintf(szTmp
, "OSGThread_%u", uiNewId
);
120 szTmp
= const_cast<Char8
*>(szName
);
123 if(_fCreateThread
!= NULL
)
124 returnValue
= _fCreateThread(szTmp
, uiNewId
, bGlobal
);
133 //---------------------------------------------------------------------------
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
)
162 UInt32 uiNewId
= _uiCondVarCount
++;
163 CondVar
*returnValue
= NULL
;
167 szTmp
= new Char8
[32];
168 sprintf(szTmp
, "OSGCondVar_%u", uiNewId
);
172 szTmp
= const_cast<Char8
*>(szName
);
175 if(_fCreateCondVar
!= NULL
)
176 returnValue
= _fCreateCondVar(szTmp
, uiNewId
, bGlobal
);
186 //---------------------------------------------------------------------------
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
)
215 UInt32 uiNewId
= _uiBarrierCount
++;
216 Barrier
*returnValue
= NULL
;
220 szTmp
= new Char8
[32];
221 sprintf(szTmp
, "OSGBarrier_%u", uiNewId
);
225 szTmp
= const_cast<Char8
*>(szName
);
228 if(_fCreateBarrier
!= NULL
)
229 returnValue
= _fCreateBarrier(szTmp
, uiNewId
, bGlobal
);
240 //---------------------------------------------------------------------------
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
)
269 UInt32 uiNewId
= _uiLockCount
++;
270 Lock
*returnValue
= NULL
;
274 szTmp
= new Char8
[32];
275 sprintf(szTmp
, "OSGLock_%u", uiNewId
);
279 szTmp
= const_cast<Char8
*>(szName
);
282 if(_fCreateLock
!= NULL
)
283 returnValue
= _fCreateLock(szTmp
, uiNewId
, bGlobal
);
294 //---------------------------------------------------------------------------
296 //---------------------------------------------------------------------------
298 /*! \class OSG::MPLockPoolType
301 UInt32
MPLockPoolType::_uiLockPoolCount
= 0;
304 MPLockPoolType::MPLockPoolType(
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
)
325 UInt32 uiNewId
= _uiLockPoolCount
++;
326 LockPool
*returnValue
= NULL
;
330 szTmp
= new Char8
[32];
331 sprintf(szTmp
, "OSGThread_%u", uiNewId
);
335 szTmp
= const_cast<Char8
*>(szName
);
338 if(_fCreateLockPool
!= NULL
)
339 returnValue
= _fCreateLockPool(szTmp
, uiNewId
, bGlobal
);
349 //---------------------------------------------------------------------------
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
)
378 UInt32 uiNewId
= _uiSemaphoreCount
++;
379 Semaphore
*returnValue
= NULL
;
383 szTmp
= new Char8
[32];
384 sprintf(szTmp
, "OSGSemaphore_%u", uiNewId
);
388 szTmp
= const_cast<Char8
*>(szName
);
391 if(_fCreateSemaphore
!= NULL
)
392 returnValue
= _fCreateSemaphore(szTmp
, uiNewId
, bGlobal
);
401 //---------------------------------------------------------------------------
403 //---------------------------------------------------------------------------
405 /*! \class OSG::MPBase
408 MPType
MPBase::_type("OSGMPBase", NULL
);
411 const MPType
&MPBase::getStaticType(void)
417 UInt32
MPBase::getStaticTypeId(void)
423 MPType
&MPBase::getType(void)
429 const MPType
&MPBase::getType(void) const
435 UInt32
MPBase::getTypeId(void)
437 return getType().getId();
441 const Char8
*MPBase::getCName(void) const
447 MPBase::MPBase(const Char8
*szName
, bool bGlobal
) :
453 osgStringDup(szName
, _szName
);
457 MPBase::~MPBase(void)