00001 #if   !defined(__SEMAPHORECOMMON_HPP)
00002 #define __SEMAPHORECOMMON_HPP
00003 
00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018 00019 00020 00021 00022 
00023 
00024 #if !defined(__COMMON_HPP)
00025 #include <Common.hpp>
00026 #endif
00027 
00028 namespace corelinux
00029 {
00034   struct   _CSAHeader
00035   {
00036     Int      creatorId;        
00037     Int      currentUsed;      
00038     Int      currentGrps;      
00039     Int      reserved;         
00040   };
00041 
00042   DECLARE_TYPE( struct _CSAHeader, CSAHeader );
00043 
00048   struct   _CSAGroupHeader
00049   {
00050     Int   groupInfo;           
00051     Int   groupShares;         
00052     Int   groupType;           
00053     Int   groupSemCount;       
00054     
00055   };
00056 
00057   DECLARE_TYPE( struct _CSAGroupHeader, CSAGrpHeader );
00058 
00063   struct   _CSASemaphoreHeader
00064   {
00065     Int   semOwner;            
00066     Int   maxSemValue;         
00067     Word  isRecursive;         
00068     Word  isBalking;           
00069     Int   semShares;           
00070   };
00071 
00072   DECLARE_TYPE( struct _CSASemaphoreHeader, CSASemHeader );
00073 
00074   DECLARE_CLASS( CoreLinuxGuardPool );
00075 
00076   DECLARE_CLASS( SemaphoreGroup );
00077 
00078   DECLARE_CLASS( MemoryStorage );
00079 
00080   DECLARE_CLASS( SemaphoreCommon );
00081 
00089   class SemaphoreCommon : public Synchronized
00090   {
00091   public:
00092 
00093     
00094     
00095     
00096 
00105     static   Int   getSemaphoreMaxValue( SemaphoreGroupPtr, Int );
00106 
00107     
00108     
00109     00118     static   void  groupDefined( SemaphoreGroupPtr );
00119 
00128     static   Int   groupUnDefined( SemaphoreGroupPtr );
00129 
00140     static   Int   setLock( SemaphoreGroupPtr, Int, Int, Int );
00141 
00152     static   Int   setUnLock( SemaphoreGroupPtr, Int, Int, Int );
00153 
00165     static   Int   obtainSemaphore
00166     (
00167      SemaphoreGroupPtr,
00168      Int,
00169      IntRef,
00170      IntRef,
00171      IntRef,
00172      Int
00173      );
00174                
00184     static   Int   relinquishSemaphore(SemaphoreGroupPtr,Int);
00185 
00194     static   Int   setMaxValue( SemaphoreGroupPtr, Int, Int );
00195 
00196 
00197 
00198   protected:
00199 
00201 
00202     SemaphoreCommon( void );
00203 
00205 
00206     virtual           ~SemaphoreCommon( void );
00207 
00208     
00209     
00210     
00211 
00218     void  registerGroup( SemaphoreGroupPtr );
00219 
00226     Int   deregisterGroup( SemaphoreGroupPtr );
00227 
00239     Int   claimSemaphore
00240     (
00241      SemaphoreGroupPtr,
00242      Int,
00243      IntRef,
00244      IntRef,
00245      IntRef,
00246      Int
00247      );
00248 
00257     Int   reclaimSemaphore(SemaphoreGroupPtr,Int);
00258 
00259 
00261 
00262     CSAGrpHeaderPtr   findGroup
00263     ( 
00264      IntCref , 
00265      IntCref , 
00266      CSAGrpHeaderPtr 
00267      );
00268 
00270 
00271     CSAGrpHeaderPtr   findAvailableGroup
00272     ( 
00273      IntCref , 
00274      IntCref , 
00275      CSAGrpHeaderPtr 
00276      );
00277 
00279 
00280     CSAGrpHeaderPtr   subsetGroup( Int, CSAGrpHeaderPtr ) ;
00281 
00282     CSAGrpHeaderPtr   combineGroup( Int, CSAGrpHeaderPtr ) ;
00283 
00284     bool  isOriginator( void ) const;
00285 
00286     Int   getOriginatorId( void ) const;
00287 
00288     Int   canonicalUndefined( void );
00289 
00290 
00292 
00293     static   void  createAttachment( void );
00294 
00295     friend   class CoreLinuxGuardPool;
00296 
00298 
00299     static   void  exitAttachment( void );
00300 
00301 
00302   private:
00303 
00304     SemaphoreCommon( SemaphoreCommonCref )
00305       throw ( Assertion )
00306       :
00307       Synchronized()
00308     {
00309       NEVER_GET_HERE;
00310     }
00311 
00312   private:
00313 
00314     MemoryStoragePtr     theCSA;
00315     CSAHeaderPtr         theBase;
00316     bool                 theOriginator;
00317     static   SemaphoreCommonPtr   theInstance;
00318     static   SemaphoreGroupPtr    theControlGroup;
00319     static   bool                 theInitializeFlag;
00320   };
00321 
00322 }
00323 
00324 #endif // if !defined(__SEMAPHORECOMMON_HPP)
00325 
00326 00327 00328 00329 00330 00331 00332 
00333