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 _OSGSEMAPHORE_H_
40 #define _OSGSEMAPHORE_H_
45 #include "OSGBaseTypes.h"
46 #include "OSGMPBase.h"
48 #if ! defined (OSG_USE_PTHREADS) && \
49 ! defined (OSG_USE_SPROC) && \
50 ! defined (OSG_USE_WINTHREADS)
51 #error "No threading model defined, check your system/compiler combination"
54 #if defined (OSG_USE_PTHREADS)
55 #include <semaphore.h>
59 #if defined (OSG_USE_SPROC)
60 #include <semaphore.h>
63 #include <boost/mpl/if.hpp>
67 template <class MPFieldT
>
70 //---------------------------------------------------------------------------
72 //---------------------------------------------------------------------------
74 /*! \ingroup GrpBaseMultiThreading
75 \ingroup GrpLibOSGBase
78 class OSG_BASE_DLLMAPPING SemaphoreCommonBase
: public MPBase
80 /*========================== PUBLIC =================================*/
84 /*========================= PROTECTED ===============================*/
88 typedef MPBase Inherited
;
90 UInt32 _uiSemaphoreId
;
92 /*---------------------------------------------------------------------*/
93 /*! \name Constructors */
96 SemaphoreCommonBase(void);
97 SemaphoreCommonBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
100 /*---------------------------------------------------------------------*/
101 /*! \name Destructor */
104 virtual ~SemaphoreCommonBase(void);
107 /*========================== PRIVATE ================================*/
111 /*!\brief prohibit default function (move to 'public' if needed) */
112 SemaphoreCommonBase (const SemaphoreCommonBase
&source
);
113 /*!\brief prohibit default function (move to 'public' if needed) */
114 void operator = (const SemaphoreCommonBase
&source
);
120 //---------------------------------------------------------------------------
122 //---------------------------------------------------------------------------
124 #if defined (OSG_USE_PTHREADS)
126 /*! \ingroup GrpBaseMultiThreading
127 \ingroup GrpLibOSGBase
130 class PThreadSemaphoreBase
: public SemaphoreCommonBase
132 /*========================== PUBLIC =================================*/
136 /*========================= PROTECTED ===============================*/
140 typedef SemaphoreCommonBase Inherited
;
142 /*---------------------------------------------------------------------*/
143 /*! \name Constructors */
146 PThreadSemaphoreBase(void);
147 PThreadSemaphoreBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
150 /*---------------------------------------------------------------------*/
151 /*! \name Destructor */
154 virtual ~PThreadSemaphoreBase(void);
157 /*---------------------------------------------------------------------*/
158 /*! \name Construction */
164 /*---------------------------------------------------------------------*/
165 /*! \name Destruction */
171 /*---------------------------------------------------------------------*/
172 /*! \name Semaphore */
179 /*========================== PRIVATE ================================*/
183 sem_t _pLowLevelSemaphore
;
185 /*!\brief prohibit default function (move to 'public' if needed) */
186 PThreadSemaphoreBase(const PThreadSemaphoreBase
&source
);
187 /*!\brief prohibit default function (move to 'public' if needed) */
188 void operator =(const PThreadSemaphoreBase
&source
);
191 typedef PThreadSemaphoreBase SemaphoreBase
;
193 #endif /* OSG_USE_PTHREADS */
198 //---------------------------------------------------------------------------
200 //---------------------------------------------------------------------------
202 #if defined (OSG_USE_SPROC)
204 /*! \ingroup GrpBaseMultiThreading
205 \ingroup GrpLibOSGBase
208 class SprocSemaphoreBase
: public SemaphoreCommonBase
210 /*========================== PUBLIC =================================*/
214 /*========================= PROTECTED ===============================*/
218 typedef SemaphoreCommonBase Inherited
;
220 /*---------------------------------------------------------------------*/
221 /*! \name Constructors */
224 SprocSemaphoreBase(void);
225 SprocSemaphoreBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
228 /*---------------------------------------------------------------------*/
229 /*! \name Destructor */
232 virtual ~SprocSemaphoreBase(void);
235 /*---------------------------------------------------------------------*/
236 /*! \name Construction */
242 /*---------------------------------------------------------------------*/
243 /*! \name Destruction */
249 /*---------------------------------------------------------------------*/
250 /*! \name Semaphore */
257 /*========================== PRIVATE ================================*/
261 usema_t
*_pLowLevelSema
;
263 /*!\brief prohibit default function (move to 'public' if needed) */
264 SprocSemaphoreBase(const SprocSemaphoreBase
&source
);
265 /*!\brief prohibit default function (move to 'public' if needed) */
266 void operator =(const SprocSemaphoreBase
&source
);
269 typedef SprocSemaphoreBase SemaphoreBase
;
271 #endif /* OSG_USE_SPROC */
276 //---------------------------------------------------------------------------
278 //---------------------------------------------------------------------------
280 #if defined (OSG_USE_WINTHREADS)
282 /*! \ingroup GrpBaseMultiThreading
283 \ingroup GrpLibOSGBase
286 class OSG_BASE_DLLMAPPING WinThreadSemaphoreBase
: public SemaphoreCommonBase
288 /*========================== PUBLIC =================================*/
292 /*========================= PROTECTED ===============================*/
296 typedef SemaphoreCommonBase Inherited
;
298 /*---------------------------------------------------------------------*/
299 /*! \name Constructors */
302 WinThreadSemaphoreBase(void);
303 WinThreadSemaphoreBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
306 /*---------------------------------------------------------------------*/
307 /*! \name Destructor */
310 virtual ~WinThreadSemaphoreBase(void);
313 /*---------------------------------------------------------------------*/
314 /*! \name Construction */
320 /*---------------------------------------------------------------------*/
321 /*! \name Destruction */
327 /*---------------------------------------------------------------------*/
328 /*! \name Semaphore */
335 /*========================== PRIVATE ================================*/
340 /*!\brief prohibit default function (move to 'public' if needed) */
341 WinThreadSemaphoreBase(const WinThreadSemaphoreBase
&source
);
342 /*!\brief prohibit default function (move to 'public' if needed) */
343 void operator =(const WinThreadSemaphoreBase
&source
);
346 typedef WinThreadSemaphoreBase SemaphoreBase
;
348 #endif /* OSG_USE_WINTHREADS */
353 //---------------------------------------------------------------------------
355 //---------------------------------------------------------------------------
357 /*! \ingroup GrpBaseMultiThreading
358 \ingroup GrpLibOSGBase
361 class OSG_BASE_DLLMAPPING Semaphore
: public SemaphoreBase
363 /*========================== PUBLIC =================================*/
367 typedef MPSemaphoreType Type
;
369 OSG_GEN_INTERNAL_MEMOBJPTR(Semaphore
);
371 /*---------------------------------------------------------------------*/
375 static ObjTransitPtr
get (const Char8
*szName
,
377 static Semaphore
*find (const Char8
*szName
);
379 static ObjTransitPtr
create ( void );
381 static const MPSemaphoreType
&getClassType( void );
384 /*---------------------------------------------------------------------*/
385 /*! \name Semaphore */
392 /*========================= PROTECTED ===============================*/
396 typedef SemaphoreBase Inherited
;
398 static MPSemaphoreType _type
;
400 /*---------------------------------------------------------------------*/
401 /*! \name Construction */
404 static Semaphore
*create(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
407 /*---------------------------------------------------------------------*/
408 /*! \name Constructors */
412 Semaphore(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
415 /*---------------------------------------------------------------------*/
416 /*! \name Destructor */
419 virtual ~Semaphore(void);
422 /*========================== PRIVATE ================================*/
426 friend class MPFieldStore
<Semaphore
>;
428 /*!\brief prohibit default function (move to 'public' if needed) */
429 Semaphore(const Semaphore
&source
);
430 /*!\brief prohibit default function (move to 'public' if needed) */
431 void operator =(const Semaphore
&source
);
434 OSG_GEN_MEMOBJPTR(Semaphore
);
438 #include "OSGSemaphore.inl"
440 #endif /* _OSGSEMAPHORE_H_ */