00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039 #ifndef _OSGBARRIER_H_
00040 #define _OSGBARRIER_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044
00045 #include "OSGBaseTypes.h"
00046 #include "OSGMPBase.h"
00047
00048 #if ! defined (OSG_USE_PTHREADS) && \
00049 ! defined (OSG_USE_SPROC) && \
00050 ! defined (OSG_USE_WINTHREADS)
00051 #error "No threading model defined, check your system/compiler combination"
00052 #endif
00053
00054 #if defined (OSG_USE_PTHREADS)
00055 #include <pthread.h>
00056 #endif
00057
00058 #if defined (OSG_USE_SPROC)
00059 #include <ulocks.h>
00060 #endif
00061
00062 OSG_BEGIN_NAMESPACE
00063
00064 template <class MPFieldT>
00065 class MPFieldStore;
00066
00067
00068
00069
00070
00074 class OSG_BASE_DLLMAPPING BarrierCommonBase : public MPBase
00075 {
00076
00077
00078 public:
00079
00080
00081
00082 protected:
00083
00084 typedef MPBase Inherited;
00085
00086 UInt32 _uiBarrierId;
00087 volatile UInt32 _uiNumWaitFor;
00088
00089
00093 BarrierCommonBase(const Char8 *szName, UInt32 uiId);
00094
00096
00100 virtual ~BarrierCommonBase(void);
00101
00103
00107 void setNumWaitFor(UInt32 uiNumWaitFor);
00108
00110
00111 private:
00112
00114 BarrierCommonBase(const BarrierCommonBase &source);
00116 void operator =(const BarrierCommonBase &source);
00117 };
00118
00119
00120
00121
00122
00123
00124
00125
00126 #if defined (OSG_USE_PTHREADS)
00127
00131 class PThreadBarrierBase : public BarrierCommonBase
00132 {
00133
00134
00135 public:
00136
00137
00138
00139 protected:
00140
00141 typedef BarrierCommonBase Inherited;
00142
00143
00147 PThreadBarrierBase(const Char8 *szName, UInt32 uiId);
00148
00150
00154 virtual ~PThreadBarrierBase(void);
00155
00157
00161 bool init ( void );
00162
00164
00168 void shutdown( void );
00169
00171
00175 void enter (void );
00176 void enter (UInt32 uiNumWaitFor);
00177
00179
00180
00181 private:
00182
00183 pthread_mutex_t _pLockOne;
00184 pthread_cond_t _pWakeupCondition[2];
00185 UInt32 _uiCount;
00186 UInt32 _uiCurrentCond;
00187
00189 PThreadBarrierBase(const PThreadBarrierBase &source);
00191 void operator =(const PThreadBarrierBase &source);
00192 };
00193
00194 typedef PThreadBarrierBase BarrierBase;
00195
00196 #endif
00197
00198
00199
00200
00201
00202
00203
00204
00205 #if defined (OSG_USE_SPROC)
00206
00210 class SprocBarrierBase : public BarrierCommonBase
00211 {
00212
00213
00214 public:
00215
00216
00217
00218 protected:
00219
00220 typedef BarrierCommonBase Inherited;
00221
00222
00226 SprocBarrierBase(const Char8 *szName, UInt32 uiId);
00227
00229
00233 virtual ~SprocBarrierBase(void);
00234
00236
00240 bool init (void );
00241
00243
00247 void shutdown(void );
00248
00250
00254 void enter (void );
00255 void enter (UInt32 uiNumWaitFor);
00256
00258
00259
00260 private:
00261
00262 barrier_t *_pBarrier;
00263
00265 SprocBarrierBase(const SprocBarrierBase &source);
00267 void operator =(const SprocBarrierBase &source);
00268 };
00269
00270 typedef SprocBarrierBase BarrierBase;
00271
00272 #endif
00273
00274
00275
00276
00277
00278
00279
00280
00281 #if defined (OSG_USE_WINTHREADS)
00282
00286 class OSG_BASE_DLLMAPPING WinThreadBarrierBase : public BarrierCommonBase
00287 {
00288
00289
00290 public:
00291
00292
00293
00294 protected:
00295
00296
00300 WinThreadBarrierBase(const Char8 *szName, UInt32 uiId);
00301
00303
00307 virtual ~WinThreadBarrierBase(void);
00308
00310
00314 bool init (void );
00315
00317
00321 void shutdown(void );
00322
00324
00328 void enter (void );
00329 void enter (UInt32 uiNumWaitFor);
00330
00332
00333
00334 private:
00335
00336 typedef BarrierCommonBase Inherited;
00337
00338 Handle _pMutex1;
00339 Handle _pBarrierSema;
00340 volatile UInt32 _uiNumWaiters;
00341
00343 WinThreadBarrierBase(const WinThreadBarrierBase &source);
00345 void operator =(const WinThreadBarrierBase &source);
00346 };
00347
00348 typedef WinThreadBarrierBase BarrierBase;
00349
00350 #endif
00351
00352
00353
00354
00355
00356
00357
00358
00362 class OSG_BASE_DLLMAPPING Barrier : public BarrierBase
00363 {
00364
00365
00366 public:
00367
00368 typedef MPBarrierType Type;
00369
00370
00374 static Barrier *get (const Char8 *szName);
00375 static Barrier *find (const Char8 *szName);
00376
00377 static Barrier *create ( void );
00378
00379 static const MPBarrierType &getClassType( void );
00380
00382
00386 void enter(void );
00387 void enter(UInt32 uiNumWaitFor);
00388
00390
00391
00392 protected:
00393
00394 typedef BarrierBase Inherited;
00395
00396 static MPBarrierType _type;
00397
00398
00402 Barrier(const Char8 *szName, UInt32 uiId);
00403
00405
00409 virtual ~Barrier(void);
00410
00412
00416 static Barrier *create(const Char8 *szName,
00417 UInt32 uiId);
00418
00420
00421
00422 private:
00423
00424 friend class MPFieldStore<Barrier>;
00425
00427 Barrier(const Barrier &source);
00429 void operator =(const Barrier &source);
00430 };
00431
00432 OSG_END_NAMESPACE
00433
00434 #define OSGBARRIER_HEADER_CVSID "@(#)$Id: $"
00435
00436 #include "OSGBarrier.inl"
00437
00438 #endif