Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

OSGThread.h

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002  *                                OpenSG                                     *
00003  *                                                                           *
00004  *                                                                           *
00005  *             Copyright (C) 2000-2002 by the OpenSG Forum                   *
00006  *                                                                           *
00007  *                            www.opensg.org                                 *
00008  *                                                                           *
00009  *   contact: dirk@opensg.org, gerrit.voss@vossg.org, jbehr@zgdv.de          *
00010  *                                                                           *
00011 \*---------------------------------------------------------------------------*/
00012 /*---------------------------------------------------------------------------*\
00013  *                                License                                    *
00014  *                                                                           *
00015  * This library is free software; you can redistribute it and/or modify it   *
00016  * under the terms of the GNU Library General Public License as published    *
00017  * by the Free Software Foundation, version 2.                               *
00018  *                                                                           *
00019  * This library is distributed in the hope that it will be useful, but       *
00020  * WITHOUT ANY WARRANTY; without even the implied warranty of                *
00021  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
00022  * Library General Public License for more details.                          *
00023  *                                                                           *
00024  * You should have received a copy of the GNU Library General Public         *
00025  * License along with this library; if not, write to the Free Software       *
00026  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                 *
00027  *                                                                           *
00028 \*---------------------------------------------------------------------------*/
00029 /*---------------------------------------------------------------------------*\
00030  *                                Changes                                    *
00031  *                                                                           *
00032  *                                                                           *
00033  *                                                                           *
00034  *                                                                           *
00035  *                                                                           *
00036  *                                                                           *
00037 \*---------------------------------------------------------------------------*/
00038 
00039 #ifndef _OSGTHREAD_H_
00040 #define _OSGTHREAD_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #ifdef OSG_DOC_FILES_IN_MODULE
00046 
00049 #endif
00050 
00051 #include <OSGSystemDef.h>
00052 #include <OSGBaseTypes.h>
00053 #include <OSGBaseThread.h>
00054 
00055 #include <utility>
00056 
00057 #include <OSGBaseTypes.h>
00058 
00059 #if ! defined (OSG_USE_PTHREADS)   && \
00060     ! defined (OSG_USE_SPROC)      && \
00061     ! defined (OSG_USE_WINTHREADS)
00062 #error "No threading model defined, check your system/compiler combination"
00063 #endif
00064 
00065 #ifdef OSG_USE_PTHREADS
00066 #   ifdef OSG_USE_SPROC
00067 #       error  "PTHREAD and SPROC threading models defined. This is a bug!"
00068 #   endif
00069 #   ifdef OSG_USE_WINTHREADS
00070 #       error  "PTHREAD and WINTHREADS threading models defined. This is a bug!"
00071 #   endif
00072 #elif defined(OSG_USE_SPROC)
00073 #   ifdef OSG_USE_WINTHREADS
00074 #       error  "SPROC and WINTHREADS threading models defined. This is a bug!"
00075 #   endif
00076 #endif
00077 
00078 OSG_BEGIN_NAMESPACE
00079 
00080 class Thread;
00081 class ChangeList;
00082 
00083 //---------------------------------------------------------------------------
00084 //  Class
00085 //---------------------------------------------------------------------------
00086 
00090 class OSG_SYSTEMLIB_DLLMAPPING ThreadCommonBase : public BaseThread
00091 {
00092     /*==========================  PUBLIC  =================================*/
00093 
00094   public :
00095 
00096     static const UInt32 InvalidAspect;
00097 
00098     /*---------------------------------------------------------------------*/
00102     ChangeList *getChangeList(void);
00103 
00105     /*=========================  PROTECTED  ===============================*/
00106 
00107   protected:
00108 
00109     typedef BaseThread Inherited;
00110 
00111     /*---------------------------------------------------------------------*/
00115     UInt32      _uiAspectId;
00116     ChangeList *_pChangeList;
00117 
00119     /*---------------------------------------------------------------------*/
00123     ThreadCommonBase(void);
00124     ThreadCommonBase(const Char8 *szName, UInt32 uiId);
00125 
00127     /*---------------------------------------------------------------------*/
00131     virtual ~ThreadCommonBase(void); 
00132 
00134     /*---------------------------------------------------------------------*/
00138     void setAspect    (UInt32      uiAspectId);
00139     void setChangeList(ChangeList *pChangeList);
00140 
00142     /*==========================  PRIVATE  ================================*/
00143 
00144   private:
00145 
00146     friend class ThreadManager;
00147 
00149     ThreadCommonBase(const ThreadCommonBase &source);
00151     void operator =(const ThreadCommonBase &source);
00152 };
00153 
00154 
00155 
00156 
00157 //---------------------------------------------------------------------------
00158 //  Class
00159 //---------------------------------------------------------------------------
00160 
00161 #ifdef OSG_USE_PTHREADS
00162 
00166 class PThreadBase : public ThreadCommonBase
00167 {
00168     /*==========================  PUBLIC  =================================*/
00169 
00170   public :
00171 
00172     /*---------------------------------------------------------------------*/
00176     static UInt32       getAspect           (void);
00177     static ChangeList  *getCurrentChangeList(void);
00178 
00180     /*---------------------------------------------------------------------*/
00184     bool runFunction(ThreadFuncF  fThreadFunc, 
00185                      UInt32       uiAspectId,
00186                      void        *pThreadArg);
00187 
00189     /*=========================  PROTECTED  ===============================*/
00190 
00191   protected:
00192 
00193     typedef ThreadCommonBase Inherited;
00194 
00195     /*---------------------------------------------------------------------*/
00199 #if defined(OSG_PTHREAD_ELF_TLS)
00200     static __thread UInt32      _uiTLSAspectId;
00201     static __thread ChangeList *_pTLSChangeList;
00202 #else
00203     static pthread_key_t  _aspectKey;
00204     static pthread_key_t  _changeListKey;
00205 #endif
00206 
00208     /*---------------------------------------------------------------------*/
00212 #if !defined(OSG_PTHREAD_ELF_TLS)
00213     static void  freeAspect    (void *pAspect);
00214     static void  freeChangeList(void *pChangeList);
00215 #endif
00216 
00218     /*---------------------------------------------------------------------*/
00222     PThreadBase(const Char8 *szName, UInt32 uiId);
00223 
00225     /*---------------------------------------------------------------------*/
00229     virtual ~PThreadBase(void); 
00230 
00232     /*---------------------------------------------------------------------*/
00236     virtual void init           (void);
00237     
00238             void setupAspect    (void);
00239             void setupChangeList(void);
00240 
00242     /*==========================  PRIVATE  ================================*/
00243 
00244   private:
00245 
00246     friend class ThreadManager;
00247 
00249     PThreadBase(const PThreadBase &source);
00251     void operator =(const PThreadBase &source);
00252 };
00253 
00254 typedef PThreadBase ThreadBase;
00255 
00256 #endif /* OSG_USE_PTHREADS */
00257 
00258 
00259 
00260 
00261 //---------------------------------------------------------------------------
00262 //  Class
00263 //---------------------------------------------------------------------------
00264 
00265 #ifdef OSG_USE_SPROC
00266 
00270 class SprocBase : public ThreadCommonBase
00271 {
00272     /*==========================  PUBLIC  =================================*/
00273 
00274   public :
00275 
00276     /*---------------------------------------------------------------------*/
00280     static UInt32      getAspect           (void);
00281     static ChangeList *getCurrentChangeList(void);
00282 
00284     /*---------------------------------------------------------------------*/
00288     bool runFunction(ThreadFuncF  fThreadFunc, 
00289                      UInt32       uiAspectId,
00290                      void        *pThreadArg);
00291 
00293     /*=========================  PROTECTED  ===============================*/
00294 
00295   protected:
00296 
00297     typedef ThreadCommonBase Inherited;
00298 
00299     struct OSGProcessData : public ProcessData
00300     {
00301         UInt32      _uiAspectId;
00302         ChangeList *_pChangeList;
00303     };
00304 
00305     /*---------------------------------------------------------------------*/
00309     SprocBase(const Char8 *szName, UInt32 uiId);
00310 
00312     /*---------------------------------------------------------------------*/
00316     virtual ~SprocBase(void); 
00317 
00319     /*---------------------------------------------------------------------*/
00323     void setAspectInternal(UInt32 uiAspect);
00324 
00326     /*---------------------------------------------------------------------*/
00330     virtual void init                   (void);
00331 
00332             void setupChangeListInternal(void);
00333 
00335     /*=========================  PROTECTED  ===============================*/
00336 
00337   private:
00338 
00339     friend class ThreadManager;
00340 
00342     SprocBase(const SprocBase &source);
00344     void operator =(const SprocBase &source);
00345 };
00346 
00347 typedef SprocBase ThreadBase;
00348 
00349 #endif /* OSG_USE_SPROC */
00350 
00351 
00352 
00353 
00354 //---------------------------------------------------------------------------
00355 //  Class
00356 //---------------------------------------------------------------------------
00357 
00358 #ifdef OSG_USE_WINTHREADS
00359 
00363 class OSG_SYSTEMLIB_DLLMAPPING WinThreadBase : public ThreadCommonBase
00364 {
00365     /*==========================  PUBLIC  =================================*/
00366 
00367   public :
00368 
00369     /*---------------------------------------------------------------------*/
00373     static UInt32      getAspect           (void);
00374     static ChangeList *getCurrentChangeList(void);
00375 
00377     /*---------------------------------------------------------------------*/
00381     bool runFunction(ThreadFuncF  fThreadFunc, 
00382                      UInt32       uiAspectId,
00383                      void        *pThreadArg);
00384 
00386     /*=========================  PROTECTED  ===============================*/
00387 
00388   protected:
00389 
00390     typedef ThreadCommonBase Inherited;
00391 
00392     /*---------------------------------------------------------------------*/
00396 #if defined(OSG_ASPECT_USE_LOCALSTORAGE)
00397     static UInt32 _aspectKey;
00398     static UInt32 _changeListKey;
00399 #endif
00400 #if defined(OSG_ASPECT_USE_DECLSPEC)
00401     static __declspec (thread) UInt32      _uiAspectLocal;
00402     static __declspec (thread) ChangeList *_pChangeListLocal;
00403 #endif
00404 
00405 #ifdef OSG_ASPECT_USE_LOCALSTORAGE
00407     /*---------------------------------------------------------------------*/
00411     static void freeAspect    (void);
00412     static void freeChangeList(void);
00413 #endif
00414 
00416     /*---------------------------------------------------------------------*/
00420     WinThreadBase(const Char8 *szName, UInt32 uiId);
00421 
00423     /*---------------------------------------------------------------------*/
00427     virtual ~WinThreadBase(void); 
00428 
00430     /*---------------------------------------------------------------------*/
00434     virtual void init            (void);
00435 
00436             void setupAspect     (void);
00437             void setupChangeList (void);
00438 
00440     /*==========================  PRIVATE  ================================*/
00441 
00442   private:
00443 
00444     friend class ThreadManager;
00445 
00447     WinThreadBase(const WinThreadBase &source);
00449     void operator =(const WinThreadBase &source);
00450 };
00451 
00452 typedef WinThreadBase ThreadBase;
00453 
00454 #endif /* OSG_USE_WINTHREADS */
00455 
00456 
00457 
00458 
00459 //---------------------------------------------------------------------------
00460 //  Class
00461 //---------------------------------------------------------------------------
00462 
00466 class OSG_SYSTEMLIB_DLLMAPPING Thread : public ThreadBase
00467 {
00468     /*=========================  PROTECTED  ===============================*/
00469 
00470   protected:
00471 
00472     typedef ThreadBase Inherited;
00473 
00474     /*==========================  PUBLIC  =================================*/
00475 
00476   public :
00477 
00478     typedef      MPThreadType Type;
00479 
00480     /*---------------------------------------------------------------------*/
00484     static ThreadBase *getCurrent(      void         );
00485 
00486     static Thread     *get       (const Char8 *szName);
00487     static Thread     *find      (const Char8 *szName);
00488 
00490     /*---------------------------------------------------------------------*/
00494     void run(UInt32 uiAspectId);
00495 
00497     /*=========================  PROTECTED  ===============================*/
00498 
00499   protected:
00500 
00501     /*---------------------------------------------------------------------*/
00505     static MPThreadType _type;
00506 
00508     /*---------------------------------------------------------------------*/
00512     static Thread *create       (const Char8 *szName, UInt32 uiId);
00513 
00514     static void    initThreading(void);
00515 
00517     /*---------------------------------------------------------------------*/
00521     Thread(const Char8 *szName, UInt32 uiId);
00522 
00524     /*---------------------------------------------------------------------*/
00528     virtual ~Thread(void);
00529 
00531     /*==========================  PRIVATE  ================================*/
00532 
00533   private:
00534 
00535     friend class ThreadManager;
00536     friend class MPFieldStore<BaseThread>;
00537 
00539     Thread(const Thread &source);
00541     void operator =(const Thread &source);
00542 };
00543 
00544 
00545 
00546 //---------------------------------------------------------------------------
00547 //  Class
00548 //---------------------------------------------------------------------------
00549 
00553 class OSG_SYSTEMLIB_DLLMAPPING ExternalThread : public ThreadBase
00554 {
00555     /*==========================  PUBLIC  =================================*/
00556 
00557   public :
00558 
00559     typedef MPThreadType Type;
00560 
00561     /*---------------------------------------------------------------------*/
00565     static ThreadBase     *getCurrent(      void         );
00566 
00567     static ExternalThread *get       (const Char8 *szName);
00568     static ExternalThread *find      (const Char8 *szName);
00569 
00571     /*---------------------------------------------------------------------*/
00575     void initialize   (UInt32 uiAspectId);
00576 
00578     /*=========================  PROTECTED  ===============================*/
00579 
00580   protected:
00581 
00582     typedef ThreadBase Inherited;
00583 
00584     /*---------------------------------------------------------------------*/
00588     static MPThreadType _type;
00589 
00591     /*---------------------------------------------------------------------*/
00595     static ExternalThread *create       (const Char8 *szName, UInt32 uiId);
00596 
00597 //    static void            initThreading(void);
00598 
00600     /*---------------------------------------------------------------------*/
00604     ExternalThread(const Char8 *szName, UInt32 uiId);
00605 
00607     /*---------------------------------------------------------------------*/
00611     virtual ~ExternalThread(void);
00612 
00614     /*==========================  PRIVATE  ================================*/
00615 
00616   private:
00617 
00618     friend class ThreadManager;
00619     friend class MPFieldStore<BaseThread>;
00620 
00622     ExternalThread(const ExternalThread &source);
00624     void operator =(const ExternalThread &source);
00625 };
00626 
00627 OSG_END_NAMESPACE
00628 
00629 #define OSGTHREAD_HEADER_CVSID "@(#)$Id: $"
00630 
00631 #endif /* _OSGTHREAD_H_ */

Generated on Thu Aug 25 04:11:39 2005 for OpenSG by  doxygen 1.4.3