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

OSGLock.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 _OSGLOCK_H_
00040 #define _OSGLOCK_H_
00041 #ifdef __sgi
00042 #pragma once
00043 #endif
00044 
00045 #include <OSGBase.h>
00046 #include <OSGConfig.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 #include <OSGBaseTypes.h>
00055 #include <OSGMPBase.h>
00056 
00057 #if defined (OSG_USE_PTHREADS)
00058 #include <pthread.h>
00059 #endif
00060 
00061 #if defined (OSG_USE_SPROC)
00062 #include <ulocks.h>
00063 #endif
00064 
00065 OSG_BEGIN_NAMESPACE
00066 
00067 static const UInt32 uiLockPoolSize = 32;
00068 static const UInt32 uiLockPoolMask = 0x0f80;
00069 
00070 template <class MPFieldT>
00071 class MPFieldStore;
00072 
00073 //---------------------------------------------------------------------------
00074 //  Class
00075 //---------------------------------------------------------------------------
00076 
00080 class OSG_BASE_DLLMAPPING LockCommonBase : public MPBase
00081 {
00082     /*==========================  PUBLIC  =================================*/
00083 
00084   public:
00085 
00086     /*=========================  PROTECTED  ===============================*/
00087 
00088   protected:
00089 
00090     typedef MPBase  Inherited;
00091 
00092             UInt32 _uiLockId;
00093   
00094     /*---------------------------------------------------------------------*/
00098     LockCommonBase(void);
00099     LockCommonBase(const Char8 *szName, UInt32 uiId);
00100     
00102     /*---------------------------------------------------------------------*/
00106     virtual ~LockCommonBase(void); 
00107     
00109     /*==========================  PRIVATE  ================================*/
00110 
00111   private:
00112 
00114     LockCommonBase  (const LockCommonBase &source);
00116     void operator = (const LockCommonBase &source);
00117 };
00118 
00119 
00120 
00121 
00122 //---------------------------------------------------------------------------
00123 //  Class
00124 //---------------------------------------------------------------------------
00125 
00126 #if defined (OSG_USE_PTHREADS)
00127 
00131 class PThreadLockBase : public LockCommonBase
00132 {
00133     /*==========================  PUBLIC  =================================*/
00134 
00135   public :
00136 
00137     /*=========================  PROTECTED  ===============================*/
00138 
00139   protected:
00140 
00141     typedef LockCommonBase Inherited;
00142     
00143     /*---------------------------------------------------------------------*/
00147     PThreadLockBase(void);
00148     PThreadLockBase(const Char8 *szName, UInt32 uiId  );
00149     
00151     /*---------------------------------------------------------------------*/
00155     virtual ~PThreadLockBase(void); 
00156 
00158     /*---------------------------------------------------------------------*/
00162     bool init    (void);
00163 
00165     /*---------------------------------------------------------------------*/
00169     void shutdown(void);
00170 
00172     /*---------------------------------------------------------------------*/
00176     void aquire  (void);
00177     void release (void);
00178     bool request (void);
00179     
00181     /*==========================  PRIVATE  ================================*/
00182 
00183   private:
00184     
00185     friend class LockPool;
00186 
00187     pthread_mutex_t _pLowLevelLock;
00188 
00190     PThreadLockBase(const PThreadLockBase &source);
00192     void operator =(const PThreadLockBase &source);
00193 };
00194 
00195 typedef PThreadLockBase LockBase;
00196 
00197 #endif /* OSG_USE_PTHREADS */
00198 
00199 
00200 
00201 
00202 //---------------------------------------------------------------------------
00203 //  Class
00204 //---------------------------------------------------------------------------
00205 
00206 #if defined (OSG_USE_SPROC)
00207 
00211 class SprocLockBase : public LockCommonBase
00212 {
00213     /*==========================  PUBLIC  =================================*/
00214 
00215   public :
00216     
00217     /*=========================  PROTECTED  ===============================*/
00218 
00219   protected:
00220 
00221     typedef LockCommonBase Inherited;
00222 
00223     /*---------------------------------------------------------------------*/
00227     SprocLockBase(void);
00228     SprocLockBase(const Char8 *szName, UInt32 uiId  );
00229     
00231     /*---------------------------------------------------------------------*/
00235     virtual ~SprocLockBase(void); 
00236 
00238     /*---------------------------------------------------------------------*/
00242     bool init    (void);
00243 
00245     /*---------------------------------------------------------------------*/
00249     void shutdown(void);
00250     
00252     /*---------------------------------------------------------------------*/
00256     void aquire  (void);
00257     void release (void);
00258     bool request (void);
00259 
00261     /*==========================  PRIVATE  ================================*/
00262 
00263   private:
00264 
00265     friend class LockPool;
00266 
00267 //#define OSG_SPROC_USE_LOCK
00268 #ifdef OSG_SPROC_USE_LOCK
00269     ulock_t  _pLowLevelLock;
00270 #else
00271     usema_t *_pLowLevelSema;
00272 #endif
00273 
00275     SprocLockBase(const SprocLockBase &source);
00277     void operator =(const SprocLockBase &source);
00278 };
00279 
00280 typedef SprocLockBase LockBase;
00281 
00282 #endif /* OSG_USE_SPROC */
00283 
00284 
00285 
00286 
00287 //---------------------------------------------------------------------------
00288 //  Class
00289 //---------------------------------------------------------------------------
00290 
00291 #if defined (OSG_USE_WINTHREADS)
00292 
00293 #if _WIN32_WINNT < 0x0400
00294 #define OSG_WINLOCK_USE_MUTEX
00295 #endif
00296 
00300 class OSG_BASE_DLLMAPPING WinThreadLockBase : public LockCommonBase
00301 {
00302     /*==========================  PUBLIC  =================================*/
00303 
00304   public :
00305 
00306     /*=========================  PROTECTED  ===============================*/
00307 
00308   protected:
00309 
00310     typedef LockCommonBase Inherited;
00311     
00312     /*---------------------------------------------------------------------*/
00316     WinThreadLockBase(void);
00317     WinThreadLockBase(const Char8 *szName, UInt32 uiId  );
00318     
00320     /*---------------------------------------------------------------------*/
00324     virtual ~WinThreadLockBase(void); 
00325 
00327     /*---------------------------------------------------------------------*/
00331     bool init    (void);
00332 
00334     /*---------------------------------------------------------------------*/
00338     void shutdown(void);
00339 
00341     /*---------------------------------------------------------------------*/
00345     void aquire  (void);
00346     void release (void);
00347     bool request (void);
00348     
00350     /*==========================  PRIVATE  ================================*/
00351   private:
00352 
00353     friend class LockPool;
00354 
00355 #ifdef OSG_WINLOCK_USE_MUTEX
00356     Handle  _pMutex;
00357 #else
00358     CRITICAL_SECTION _pCriticalSection;
00359 #endif
00360   
00362     WinThreadLockBase(const WinThreadLockBase &source);
00364     void operator =(const WinThreadLockBase &source);
00365 };
00366 
00367 typedef WinThreadLockBase LockBase;
00368 
00369 #endif /* OSG_USE_WINTHREADS */
00370 
00371 
00372 
00373 
00374 //---------------------------------------------------------------------------
00375 //  Class
00376 //---------------------------------------------------------------------------
00377 
00381 class OSG_BASE_DLLMAPPING Lock : public LockBase
00382 {
00383     /*==========================  PUBLIC  =================================*/
00384 
00385   public:
00386 
00387     typedef MPLockType Type;
00388 
00389     /*---------------------------------------------------------------------*/
00393     static       Lock       *get         (const Char8 *szName);
00394     static       Lock       *find        (const Char8 *szName);
00395 
00396     static       Lock       *create      (      void         );
00397 
00398     static const MPLockType &getClassType(      void         ); 
00399 
00401     /*---------------------------------------------------------------------*/
00405     void aquire (void);
00406     void release(void);
00407     bool request(void);
00408     
00410     /*=========================  PROTECTED  ===============================*/
00411 
00412   protected:
00413 
00414     typedef LockBase    Inherited;
00415 
00416     static  MPLockType _type;
00417   
00418     /*---------------------------------------------------------------------*/
00422     static Lock *create(const Char8 *szName, UInt32 uiId);
00423 
00425     /*---------------------------------------------------------------------*/
00429     Lock(void);
00430     Lock(const Char8 *szName, UInt32 uiId);
00431     
00433     /*---------------------------------------------------------------------*/
00437     virtual ~Lock(void);
00438 
00440     /*==========================  PRIVATE  ================================*/
00441 
00442   private:
00443 
00444     friend class LockPool;
00445     friend class MPFieldStore<Lock>;
00446 
00448     Lock(const Lock &source);
00450     void operator =(const Lock &source);
00451 };
00452 
00453 
00454 
00455 
00456 //---------------------------------------------------------------------------
00457 //  Class
00458 //---------------------------------------------------------------------------
00459 
00463 class OSG_BASE_DLLMAPPING LockPool : public LockCommonBase
00464 {
00465     /*==========================  PUBLIC  =================================*/
00466 
00467   public:
00468 
00469     typedef MPLockPoolType Type;
00470 
00471     /*---------------------------------------------------------------------*/
00475     static LockPool *get   (const Char8 *szName);
00476     static LockPool *find  (const Char8 *szName);
00477     static LockPool *create(      void         );
00478 
00480     /*---------------------------------------------------------------------*/
00484     void aquire (void *keyP);
00485     void release(void *keyP);
00486     bool request(void *keyP);
00487     
00489     /*=========================  PROTECTED  ===============================*/
00490 
00491   protected:
00492 
00493     typedef LockCommonBase  Inherited;
00494 
00495     static  MPLockPoolType _type;
00496 
00497             Lock           _pLocks    [uiLockPoolSize];
00498 
00499 #ifdef OSG_DEBUG_LOCK_STAT
00500             UInt32         _pLockStats[uiLockPoolSize];
00501 #endif
00502 
00503     /*---------------------------------------------------------------------*/
00507     static LockPool *create(const Char8 *szName, UInt32 uiId);
00508 
00510     /*---------------------------------------------------------------------*/
00514     LockPool(const Char8 *szName, UInt32 uiId);
00515     
00517     /*---------------------------------------------------------------------*/
00521     virtual ~LockPool(void);
00522      
00524     /*---------------------------------------------------------------------*/
00528     bool init(void);
00529 
00531     /*---------------------------------------------------------------------*/
00535     void shutdown(void);
00536         
00538     /*==========================  PRIVATE  ================================*/
00539 
00540   private:
00541 
00542     friend class MPFieldStore<LockPool>;
00543 
00545     LockPool(const LockPool &source);
00547     void operator =(const LockPool &source);
00548 };
00549 
00550 OSG_END_NAMESPACE
00551 
00552 #define OSGLOCK_HEADER_CVSID "@(#)$Id: $"
00553 
00554 #endif /* _OSGLOCK_H_ */

Generated on Thu Aug 25 04:07:09 2005 for OpenSG by  doxygen 1.4.3