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 _OSGBARRIER_H_
40 #define _OSGBARRIER_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)
56 #endif /* OSG_USE_PTHREADS */
58 #if defined (OSG_USE_SPROC)
60 #endif /* OSG_USE_SPROC */
64 template <class MPFieldT
>
67 //---------------------------------------------------------------------------
69 //---------------------------------------------------------------------------
71 /*! \ingroup GrpBaseMultiThreading
72 \ingroup GrpLibOSGBase
75 class OSG_BASE_DLLMAPPING BarrierCommonBase
: public MPBase
77 /*========================== PUBLIC =================================*/
81 /*========================= PROTECTED ===============================*/
85 typedef MPBase Inherited
;
88 volatile UInt32 _uiNumWaitFor
;
90 /*---------------------------------------------------------------------*/
91 /*! \name Constructors */
94 BarrierCommonBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
97 /*---------------------------------------------------------------------*/
98 /*! \name Destructor */
101 virtual ~BarrierCommonBase(void);
104 /*---------------------------------------------------------------------*/
108 void setNumWaitFor(UInt32 uiNumWaitFor
);
111 /*========================== PRIVATE ================================*/
115 /*!\brief prohibit default function (move to 'public' if needed) */
116 BarrierCommonBase(const BarrierCommonBase
&source
);
117 /*!\brief prohibit default function (move to 'public' if needed) */
118 void operator =(const BarrierCommonBase
&source
);
124 //---------------------------------------------------------------------------
126 //---------------------------------------------------------------------------
128 #if defined (OSG_USE_PTHREADS)
130 /*! \ingroup GrpBaseMultiThreading
131 \ingroup GrpLibOSGBase
134 class PThreadBarrierBase
: public BarrierCommonBase
136 /*========================== PUBLIC =================================*/
140 /*========================= PROTECTED ===============================*/
144 typedef BarrierCommonBase Inherited
;
146 /*---------------------------------------------------------------------*/
147 /*! \name Constructors */
150 PThreadBarrierBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
153 /*---------------------------------------------------------------------*/
154 /*! \name Destructor */
157 virtual ~PThreadBarrierBase(void);
160 /*---------------------------------------------------------------------*/
161 /*! \name Construction */
167 /*---------------------------------------------------------------------*/
168 /*! \name Destruction */
171 void shutdown( void );
174 /*---------------------------------------------------------------------*/
179 void enter (UInt32 uiNumWaitFor
);
181 UInt32
getNumWaiting(void );
184 /*========================== PRIVATE ================================*/
188 pthread_mutex_t _pLockOne
;
189 pthread_cond_t _pWakeupCondition
[2];
191 UInt32 _uiCurrentCond
;
193 /*!\brief prohibit default function (move to 'public' if needed) */
194 PThreadBarrierBase(const PThreadBarrierBase
&source
);
195 /*!\brief prohibit default function (move to 'public' if needed) */
196 void operator =(const PThreadBarrierBase
&source
);
199 typedef PThreadBarrierBase BarrierBase
;
201 #endif /* OSG_USE_PTHREADS */
206 //---------------------------------------------------------------------------
208 //---------------------------------------------------------------------------
210 #if defined (OSG_USE_SPROC)
212 /*! \ingroup GrpBaseMultiThreading
213 \ingroup GrpLibOSGBase
216 class SprocBarrierBase
: public BarrierCommonBase
218 /*========================== PUBLIC =================================*/
222 /*========================= PROTECTED ===============================*/
226 typedef BarrierCommonBase Inherited
;
228 /*---------------------------------------------------------------------*/
229 /*! \name Constructors */
232 SprocBarrierBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
235 /*---------------------------------------------------------------------*/
236 /*! \name Destructor */
239 virtual ~SprocBarrierBase(void);
242 /*---------------------------------------------------------------------*/
243 /*! \name Construction */
249 /*---------------------------------------------------------------------*/
250 /*! \name Destruction */
253 void shutdown(void );
256 /*---------------------------------------------------------------------*/
261 void enter (UInt32 uiNumWaitFor
);
263 UInt32
getNumWaiting(void );
266 /*========================== PRIVATE ================================*/
270 barrier_t
*_pBarrier
;
272 /*!\brief prohibit default function (move to 'public' if needed) */
273 SprocBarrierBase(const SprocBarrierBase
&source
);
274 /*!\brief prohibit default function (move to 'public' if needed) */
275 void operator =(const SprocBarrierBase
&source
);
278 typedef SprocBarrierBase BarrierBase
;
280 #endif /* OSG_USE_SPROC */
285 //---------------------------------------------------------------------------
287 //---------------------------------------------------------------------------
289 #if defined (OSG_USE_WINTHREADS)
291 /*! \ingroup GrpBaseMultiThreading
292 \ingroup GrpLibOSGBase
295 class OSG_BASE_DLLMAPPING WinThreadBarrierBase
: public BarrierCommonBase
297 /*========================== PUBLIC =================================*/
301 /*========================= PROTECTED ===============================*/
305 /*---------------------------------------------------------------------*/
306 /*! \name Constructors */
309 WinThreadBarrierBase(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
312 /*---------------------------------------------------------------------*/
313 /*! \name Destructor */
316 virtual ~WinThreadBarrierBase(void);
319 /*---------------------------------------------------------------------*/
320 /*! \name Construction */
326 /*---------------------------------------------------------------------*/
327 /*! \name Destruction */
330 void shutdown(void );
333 /*---------------------------------------------------------------------*/
338 void enter (UInt32 uiNumWaitFor
);
340 UInt32
getNumWaiting(void );
343 /*========================== PRIVATE ================================*/
347 typedef BarrierCommonBase Inherited
;
350 Handle _pBarrierSema
[2];
352 UInt32 _uiCurrentCond
;
354 /*!\brief prohibit default function (move to 'public' if needed) */
355 WinThreadBarrierBase(const WinThreadBarrierBase
&source
);
356 /*!\brief prohibit default function (move to 'public' if needed) */
357 void operator =(const WinThreadBarrierBase
&source
);
360 typedef WinThreadBarrierBase BarrierBase
;
362 #endif /* OSG_USE_WINTHREADS */
367 //---------------------------------------------------------------------------
369 //---------------------------------------------------------------------------
371 /*! \ingroup GrpBaseMultiThreading
372 \ingroup GrpLibOSGBase
375 class OSG_BASE_DLLMAPPING Barrier
: public BarrierBase
377 /*========================== PUBLIC =================================*/
381 typedef MPBarrierType Type
;
383 OSG_GEN_INTERNAL_MEMOBJPTR(Barrier
);
385 /*---------------------------------------------------------------------*/
389 static ObjTransitPtr
get (const Char8
*szName
,
391 static Barrier
*find (const Char8
*szName
);
393 static ObjTransitPtr
create ( void );
395 static const MPBarrierType
&getClassType( void );
398 /*---------------------------------------------------------------------*/
402 void setNumWaitFor(UInt32 uiNumWaitFor
);
403 UInt32
getNumWaiting(void );
406 /*---------------------------------------------------------------------*/
411 void enter(UInt32 uiNumWaitFor
);
414 /*========================= PROTECTED ===============================*/
418 typedef BarrierBase Inherited
;
420 static MPBarrierType _type
;
422 /*---------------------------------------------------------------------*/
423 /*! \name Constructors */
426 Barrier(const Char8
*szName
, UInt32 uiId
, bool bGlobal
);
429 /*---------------------------------------------------------------------*/
430 /*! \name Destructor */
433 virtual ~Barrier(void);
436 /*---------------------------------------------------------------------*/
437 /*! \name Construction */
440 static Barrier
*create(const Char8
*szName
,
445 /*========================== PRIVATE ================================*/
449 friend class MPFieldStore
<Barrier
>;
451 /*!\brief prohibit default function (move to 'public' if needed) */
452 Barrier(const Barrier
&source
);
453 /*!\brief prohibit default function (move to 'public' if needed) */
454 void operator =(const Barrier
&source
);
457 OSG_GEN_MEMOBJPTR(Barrier
);
461 #include "OSGBarrier.inl"
463 #endif /* _OSGBARRIER_H_ */