osg::PThreadBarrierBase Class Reference
[Multithreading]

#include <OSGBarrier.h>

Inheritance diagram for osg::PThreadBarrierBase:

osg::BarrierCommonBase osg::MPBase osg::MemoryObject osg::Barrier

List of all members.

Class Specific



Char8_szName
static MPType _type

Public Member Functions

Get


virtual MPTypegetType (void)
virtual const MPTypegetType (void) const
UInt32 getTypeId (void)
const Char8getCName (void) const
Reference Counting


void addRef (void)
void subRef (void)
Int32 getRefCount (void)

Static Public Member Functions

Class Get


static const MPTypegetStaticType (void)
static UInt32 getStaticTypeId (void)

Protected Types

typedef BarrierCommonBase Inherited

Protected Member Functions

Constructors


 PThreadBarrierBase (const Char8 *szName, UInt32 uiId)
Destructor


virtual ~PThreadBarrierBase (void)
Construction


bool init (void)
Destruction


void shutdown (void)
Enter


void enter (void)
void enter (UInt32 uiNumWaitFor)
Set


void setNumWaitFor (UInt32 uiNumWaitFor)

Protected Attributes

UInt32 _uiBarrierId
volatile UInt32 _uiNumWaitFor

Private Member Functions

 PThreadBarrierBase (const PThreadBarrierBase &source)
 prohibit default function (move to 'public' if needed)
void operator= (const PThreadBarrierBase &source)
 prohibit default function (move to 'public' if needed)

Private Attributes

pthread_mutex_t _pLockOne
pthread_cond_t _pWakeupCondition [2]
UInt32 _uiCount
UInt32 _uiCurrentCond


Detailed Description

Definition at line 131 of file OSGBarrier.h.


Member Typedef Documentation

Reimplemented from osg::BarrierCommonBase.

Reimplemented in osg::Barrier.

Definition at line 141 of file OSGBarrier.h.


Constructor & Destructor Documentation

PThreadBarrierBase::PThreadBarrierBase ( const Char8 szName,
UInt32  uiId 
) [protected]

Definition at line 86 of file OSGBarrier.cpp.

00087                                                              :
00088      Inherited        (szName, 
00089                        uiId  ),
00090 
00091     _pLockOne         (      ),
00092     _uiCount          (0     ),
00093     _uiCurrentCond    (0     )
00094 {
00095 }

PThreadBarrierBase::~PThreadBarrierBase ( void   )  [protected, virtual]

Definition at line 99 of file OSGBarrier.cpp.

00100 {
00101 }

osg::PThreadBarrierBase::PThreadBarrierBase ( const PThreadBarrierBase source  )  [private]


Member Function Documentation

bool PThreadBarrierBase::init ( void   )  [protected]

Definition at line 105 of file OSGBarrier.cpp.

References _pLockOne, _pWakeupCondition, _uiCount, and _uiCurrentCond.

Referenced by osg::Barrier::create().

00106 {
00107     pthread_cond_init (&(_pWakeupCondition[0]), NULL);
00108     pthread_cond_init (&(_pWakeupCondition[1]), NULL);
00109     pthread_mutex_init(&(_pLockOne),            NULL);
00110 
00111     _uiCount       = 0;
00112     _uiCurrentCond = 0;
00113 
00114     return true;
00115 }

void PThreadBarrierBase::shutdown ( void   )  [protected]

Definition at line 119 of file OSGBarrier.cpp.

References _pLockOne, and _pWakeupCondition.

Referenced by osg::Barrier::~Barrier().

00120 {
00121     pthread_cond_destroy (&(_pWakeupCondition[0]));
00122     pthread_cond_destroy (&(_pWakeupCondition[1]));
00123     pthread_mutex_destroy(&(_pLockOne));
00124 }

void osg::PThreadBarrierBase::enter ( void   )  [inline, protected]

Reimplemented in osg::Barrier.

Definition at line 105 of file OSGBarrier.inl.

References _pLockOne, _pWakeupCondition, _uiCount, _uiCurrentCond, and osg::BarrierCommonBase::_uiNumWaitFor.

Referenced by osg::Barrier::enter(), and enter().

00107 {
00108 
00109     if(_uiNumWaitFor <= 1)
00110 
00111         return;
00112 
00113 
00114 
00115     pthread_mutex_lock(&(_pLockOne));
00116 
00117 
00118 
00119     _uiCount++;
00120 
00121 
00122 
00123     if(_uiCount < _uiNumWaitFor)
00124 
00125     {
00126 
00127         /* not enough threads are waiting => wait */
00128 
00129 
00130 
00131         pthread_cond_wait(&(_pWakeupCondition[_uiCurrentCond]), &(_pLockOne));
00132 
00133     }
00134 
00135     else
00136 
00137     {
00138 
00139         /* ok, enough threads are waiting
00140 
00141            => wake up all waiting threads
00142 
00143         */
00144 
00145 
00146 
00147         pthread_cond_broadcast(&(_pWakeupCondition[_uiCurrentCond]));
00148 
00149 
00150 
00151         _uiCount       = 0;
00152 
00153         _uiCurrentCond = 1 - _uiCurrentCond;
00154 
00155     }
00156 
00157 
00158 
00159     pthread_mutex_unlock(&(_pLockOne));
00160 
00161 }

void osg::PThreadBarrierBase::enter ( UInt32  uiNumWaitFor  )  [inline, protected]

Reimplemented in osg::Barrier.

Definition at line 167 of file OSGBarrier.inl.

References osg::BarrierCommonBase::_uiNumWaitFor, and enter().

00169 {
00170 
00171     _uiNumWaitFor = uiNumWaitFor;
00172 
00173 
00174 
00175     enter();
00176 
00177 }

void osg::PThreadBarrierBase::operator= ( const PThreadBarrierBase source  )  [private]

void osg::BarrierCommonBase::setNumWaitFor ( UInt32  uiNumWaitFor  )  [inline, protected, inherited]

Definition at line 83 of file OSGBarrier.inl.

References osg::BarrierCommonBase::_uiNumWaitFor.

00085 {
00086 
00087     _uiNumWaitFor = uiNumWaitFor;
00088 
00089 }

const MPType & MPBase::getStaticType ( void   )  [static, inherited]

Definition at line 253 of file OSGMPBase.cpp.

References osg::MPBase::_type.

00254 {
00255     return _type;
00256 }

UInt32 MPBase::getStaticTypeId ( void   )  [static, inherited]

Definition at line 259 of file OSGMPBase.cpp.

00260 {
00261     return 0;
00262 }

MPType & MPBase::getType ( void   )  [virtual, inherited]

Definition at line 265 of file OSGMPBase.cpp.

References osg::MPBase::_type.

Referenced by osg::MPBase::getTypeId().

00266 {
00267     return _type;
00268 }

const MPType & MPBase::getType ( void   )  const [virtual, inherited]

Definition at line 271 of file OSGMPBase.cpp.

References osg::MPBase::_type.

00272 {
00273     return _type;
00274 }

UInt32 MPBase::getTypeId ( void   )  [inherited]

Definition at line 277 of file OSGMPBase.cpp.

References osg::TypeBase::getId(), and osg::MPBase::getType().

00278 {
00279     return getType().getId();
00280 }

const Char8 * MPBase::getCName ( void   )  const [inherited]

Definition at line 283 of file OSGMPBase.cpp.

References osg::MPBase::_szName.

00284 {
00285     return _szName;
00286 }

void MemoryObject::addRef ( void   )  [inherited]

void MemoryObject::subRef ( void   )  [inherited]

Definition at line 69 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00070 {
00071     _refCount--;
00072 
00073     if(_refCount <= 0)
00074         delete this;
00075 }

Int32 MemoryObject::getRefCount ( void   )  [inherited]

Definition at line 77 of file OSGMemoryObject.cpp.

References osg::MemoryObject::_refCount.

00078 {
00079     return _refCount;
00080 }


Member Data Documentation

pthread_mutex_t osg::PThreadBarrierBase::_pLockOne [private]

Definition at line 183 of file OSGBarrier.h.

Referenced by enter(), init(), and shutdown().

pthread_cond_t osg::PThreadBarrierBase::_pWakeupCondition[2] [private]

Definition at line 184 of file OSGBarrier.h.

Referenced by enter(), init(), and shutdown().

Definition at line 185 of file OSGBarrier.h.

Referenced by enter(), and init().

Definition at line 186 of file OSGBarrier.h.

Referenced by enter(), and init().

Definition at line 86 of file OSGBarrier.h.

volatile UInt32 osg::BarrierCommonBase::_uiNumWaitFor [protected, inherited]

Definition at line 87 of file OSGBarrier.h.

Referenced by enter(), and osg::BarrierCommonBase::setNumWaitFor().

MPType MPBase::_type [static, protected, inherited]

Char8* osg::MPBase::_szName [protected, inherited]


The documentation for this class was generated from the following files:

Generated on Mon Mar 17 12:03:09 2008 for OpenSG by  doxygen 1.5.5