osg::BasePThreadBase Class Reference
[Multithreading]

#include <OSGBaseThread.h>

Inheritance diagram for osg::BasePThreadBase:

osg::BaseThreadCommonBase osg::MPBase osg::MemoryObject osg::BaseThread osg::ThreadCommonBase osg::PThreadBase osg::ExternalThread osg::Thread

List of all members.

Class Specific



static MPType _type
Char8_szName

Public Types

typedef void(* ThreadFuncF )(void *pThreadArg)

Public Member Functions

bool isInitialized (void)
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 BaseThreadCommonBase Inherited

Protected Member Functions

Constructors


 BasePThreadBase (const Char8 *szName, UInt32 uiId)
Destructors


virtual ~BasePThreadBase (void)
Construction


virtual void init (void)
void setupThread (void)
void setupBlockCond (void)
Run


bool runFunction (ThreadFuncF fThreadFunc, void *pThreadArg)
Blocking


void block (void)
void unblock (void)
Helper


bool exists (void)
void terminate (void)
void kill (void)
Dump


void print (void)

Static Protected Member Functions

Helper


static void * threadFunc (void *pThreadArg)
static void freeThread (void *pThread)
Get


static BaseThreadgetCurrent (void)
Join


static void join (BasePThreadBase *threadP)

Protected Attributes

UInt32 _uiThreadId
bool _bInitialized
Instance Variables


void * _pThreadData [3]
pthread_t * _pThreadDesc
pthread_cond_t * _pBlockCond
pthread_mutex_t * _pBlockMutex

Static Protected Attributes

static pthread_key_t _threadKey

Private Member Functions

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

Friends

class ThreadManager


Detailed Description

Definition at line 141 of file OSGBaseThread.h.


Member Typedef Documentation

typedef void(* osg::BaseThreadCommonBase::ThreadFuncF)(void *pThreadArg) [inherited]


Constructor & Destructor Documentation

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

Definition at line 147 of file OSGBaseThread.cpp.

References _pThreadData.

00148                                                        :
00149      Inherited  (szName, uiId),
00150 
00151     _pThreadDesc(NULL),
00152     _pBlockCond (NULL),
00153     _pBlockMutex(NULL)
00154 {
00155     _pThreadData[0] = NULL;
00156     _pThreadData[1] = NULL;
00157     _pThreadData[2] = NULL;
00158 }

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

Definition at line 163 of file OSGBaseThread.cpp.

References _pThreadDesc.

00164 {
00165     delete _pThreadDesc;
00166 }

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


Member Function Documentation

void * BasePThreadBase::threadFunc ( void *  pThreadArg  )  [static, protected]

Definition at line 114 of file OSGBaseThread.cpp.

Referenced by runFunction().

00115 {
00116     void **pArgs = (void **) pThreadArg;
00117 
00118     if(pArgs != NULL)
00119     {
00120         if(pArgs[2] != NULL)
00121         {
00122             ((BaseThread *) pArgs[2])->init();
00123 
00124             if(pArgs[0] != NULL)
00125             {
00126                 ThreadFuncF fThreadFunc = (ThreadFuncF) pArgs[0];
00127 
00128                 fThreadFunc(pArgs[1]);
00129             }
00130         }
00131     }
00132 
00133     return NULL;
00134 }

void BasePThreadBase::freeThread ( void *  pThread  )  [static, protected]

Definition at line 137 of file OSGBaseThread.cpp.

Referenced by osg::BaseThread::initThreading(), and osg::ThreadManager::shutdown().

00138 {
00139     BaseThread **pT = static_cast<BaseThread **>(pThread);
00140 
00141     delete pT;
00142 }

void BasePThreadBase::init ( void   )  [protected, virtual]

Reimplemented in osg::PThreadBase.

Definition at line 193 of file OSGBaseThread.cpp.

References osg::BaseThreadCommonBase::_bInitialized, setupBlockCond(), and setupThread().

Referenced by osg::ThreadManager::init().

00194 {
00195     if(_bInitialized == true)
00196         return;
00197 
00198     setupThread    ();
00199     setupBlockCond ();
00200 
00201     _bInitialized = true;
00202 }

void BasePThreadBase::setupThread ( void   )  [protected]

Definition at line 171 of file OSGBaseThread.cpp.

References _threadKey.

Referenced by init().

00172 {
00173 #ifdef OSG_PTHREAD_ELF_TLS
00174     _pLocalThread = static_cast<BaseThread *>(this);
00175 #else
00176     BaseThread **pThread = new BaseThread *;
00177 
00178     *pThread = (BaseThread *) this;
00179 
00180     pthread_setspecific(_threadKey, (void *) pThread);
00181 #endif
00182 }

void BasePThreadBase::setupBlockCond ( void   )  [protected]

Definition at line 184 of file OSGBaseThread.cpp.

References _pBlockCond, and _pBlockMutex.

Referenced by init().

00185 {
00186     _pBlockCond  = new pthread_cond_t;
00187     _pBlockMutex = new pthread_mutex_t;
00188 
00189     pthread_cond_init (_pBlockCond, NULL);
00190     pthread_mutex_init(_pBlockMutex, NULL);
00191 }

BaseThread * BasePThreadBase::getCurrent ( void   )  [static, protected]

Reimplemented in osg::BaseThread, osg::Thread, and osg::ExternalThread.

Definition at line 206 of file OSGBaseThread.cpp.

References _threadKey.

00207 {
00208 #ifdef OSG_PTHREAD_ELF_TLS
00209     return _pLocalThread;
00210 #else
00211     BaseThread **pThread;
00212 
00213     pThread = (BaseThread **) pthread_getspecific(_threadKey);
00214 
00215     return *pThread;
00216 #endif
00217 }

void BasePThreadBase::join ( BasePThreadBase threadP  )  [static, protected]

Definition at line 221 of file OSGBaseThread.cpp.

References _pThreadDesc.

Referenced by osg::BaseThread::join().

00222 {
00223     if(pThread != NULL && pThread->_pThreadDesc != NULL)
00224     {
00225         pthread_join(*(pThread->_pThreadDesc), NULL);
00226     }
00227 }

bool BasePThreadBase::runFunction ( ThreadFuncF  fThreadFunc,
void *  pThreadArg 
) [protected]

Reimplemented in osg::BaseThread.

Definition at line 233 of file OSGBaseThread.cpp.

References osg::BaseThreadCommonBase::_bInitialized, _pThreadData, _pThreadDesc, SFATAL, and threadFunc().

Referenced by osg::BaseThread::run(), and osg::BaseThread::runFunction().

00235 {
00236     bool  returnValue = true;
00237     Int32 rc          = 0;
00238 
00239     _bInitialized     = false;
00240 
00241     if(fThreadFunc != NULL)
00242     {
00243        if(_pThreadDesc == NULL)
00244             _pThreadDesc = new pthread_t;
00245 
00246         pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS, &rc);
00247 
00248         _pThreadData[0] = (void *) fThreadFunc;
00249         _pThreadData[1] =          pThreadArg;
00250         _pThreadData[2] = (void *) this;
00251         
00252         pthread_attr_t  threadAttr;       
00253         pthread_attr_setscope(&threadAttr, PTHREAD_SCOPE_SYSTEM);
00254 
00255         rc = pthread_create(_pThreadDesc,
00256 #if 0        
00257                             &threadAttr,
00258 #else
00259                             NULL,
00260 #endif
00261                             BasePThreadBase::threadFunc,
00262                             (void *) &_pThreadData);
00263 
00264         if(rc != 0)
00265         {
00266             SFATAL << "OSGPTB : pthread_create failed" << std::endl;
00267             returnValue = false;
00268         }
00269     }
00270     else
00271     {
00272         SFATAL << "OSGPTB : no thread function given";
00273         returnValue = false;
00274     }
00275 
00276     return returnValue;
00277 }

void BasePThreadBase::block ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 281 of file OSGBaseThread.cpp.

References _pBlockCond, and _pBlockMutex.

Referenced by osg::BaseThread::block().

00282 {
00283     pthread_mutex_lock  (_pBlockMutex);
00284     pthread_cond_wait   (_pBlockCond, _pBlockMutex);
00285     pthread_mutex_unlock(_pBlockMutex);
00286 }

void BasePThreadBase::unblock ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 288 of file OSGBaseThread.cpp.

References _pBlockCond.

Referenced by osg::BaseThread::unblock().

00289 {
00290     pthread_cond_broadcast(_pBlockCond);
00291 }

bool BasePThreadBase::exists ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 295 of file OSGBaseThread.cpp.

Referenced by osg::BaseThread::exists().

00296 {
00297     return true;
00298 }

void BasePThreadBase::terminate ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 300 of file OSGBaseThread.cpp.

References _pThreadDesc.

Referenced by osg::BaseThread::terminate().

00301 {
00302     if(_pThreadDesc != NULL)
00303         pthread_cancel(*_pThreadDesc);
00304 }

void BasePThreadBase::kill ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 306 of file OSGBaseThread.cpp.

References _pThreadDesc.

Referenced by osg::BaseThread::kill().

00307 {
00308     if(_pThreadDesc != NULL) 
00309         pthread_cancel(*_pThreadDesc);
00310 }

void BasePThreadBase::print ( void   )  [protected]

Reimplemented in osg::BaseThread.

Definition at line 314 of file OSGBaseThread.cpp.

References osg::MPBase::_szName, and osg::BaseThreadCommonBase::_uiThreadId.

Referenced by osg::BaseThread::print().

00315 {
00316     fprintf(stderr, "OSGPThreadBase -%s-%d-\n", _szName, _uiThreadId);
00317 }

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

bool BaseThreadCommonBase::isInitialized ( void   )  [inherited]

Definition at line 73 of file OSGBaseThread.cpp.

References osg::BaseThreadCommonBase::_bInitialized.

00074 {
00075     return _bInitialized;
00076 }

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 }


Friends And Related Function Documentation

friend class ThreadManager [friend]


Member Data Documentation

pthread_key_t BasePThreadBase::_threadKey [static, protected]

Definition at line 156 of file OSGBaseThread.h.

Referenced by getCurrent(), osg::BaseThread::initThreading(), and setupThread().

void* osg::BasePThreadBase::_pThreadData[3] [protected]

Definition at line 174 of file OSGBaseThread.h.

Referenced by BasePThreadBase(), and runFunction().

pthread_t* osg::BasePThreadBase::_pThreadDesc [protected]

Definition at line 175 of file OSGBaseThread.h.

Referenced by join(), kill(), runFunction(), terminate(), and ~BasePThreadBase().

pthread_cond_t* osg::BasePThreadBase::_pBlockCond [protected]

Definition at line 177 of file OSGBaseThread.h.

Referenced by block(), setupBlockCond(), and unblock().

pthread_mutex_t* osg::BasePThreadBase::_pBlockMutex [protected]

Definition at line 178 of file OSGBaseThread.h.

Referenced by block(), and setupBlockCond().

Definition at line 100 of file OSGBaseThread.h.

Referenced by print().

bool osg::BaseThreadCommonBase::_bInitialized [protected, inherited]

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 11:10:42 2008 for OpenSG by  doxygen 1.5.5