Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Examples  

SemaphoreCommon.hpp

00001 #if   !defined(__SEMAPHORECOMMON_HPP)
00002 #define __SEMAPHORECOMMON_HPP
00003 
00004 /*
00005   CoreLinux++ 
00006   Copyright (C) 1999,2000 CoreLinux Consortium
00007   
00008    The CoreLinux++ Library is free software; you can redistribute it and/or
00009    modify it under the terms of the GNU Library General Public License as
00010    published by the Free Software Foundation; either version 2 of the
00011    License, or (at your option) any later version.
00012 
00013    The CoreLinux++ Library Library is distributed in the hope that it will 
00014    be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
00015    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00016    Library General Public License for more details.
00017 
00018    You should have received a copy of the GNU Library General Public
00019    License along with the GNU C Library; see the file COPYING.LIB.  If not,
00020    write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00021    Boston, MA 02111-1307, USA.  
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;        // 0 if not opened before
00037     Int      currentUsed;      // The current used up in the pool
00038     Int      currentGrps;      // The current groups present
00039     Int      reserved;         // 
00040   };
00041 
00042   DECLARE_TYPE( struct _CSAHeader, CSAHeader );
00043 
00048   struct   _CSAGroupHeader
00049   {
00050     Int   groupInfo;           // Either an Id, 0 if tail, or -1 if available
00051     Int   groupShares;         // How many processes are using this
00052     Int   groupType;           // -1 not used, 0 Mutex, 1 Gateway, 2-10 res
00053     Int   groupSemCount;       // Semaphore count if info is -1 
00054     // and not reclaimed | !0 
00055   };
00056 
00057   DECLARE_TYPE( struct _CSAGroupHeader, CSAGrpHeader );
00058 
00063   struct   _CSASemaphoreHeader
00064   {
00065     Int   semOwner;            // Current semaphore owner
00066     Int   maxSemValue;         // 1 for mutexes, n for others, -1 if control
00067     Word  isRecursive;         // ? for instance, 0 for control
00068     Word  isBalking;           // ? for instance, 0 for control
00069     Int   semShares;           // Shares for this semaphore
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     // Accessors
00095     //
00096 
00105     static   Int   getSemaphoreMaxValue( SemaphoreGroupPtr, Int );
00106 
00107     //
00108     // Mutators
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     // Instance mutators
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    Common rcs information do not modify
00328    $Author: prudhomm $
00329    $Revision: 1.8 $
00330    $Date: 2000/08/31 22:52:20 $
00331    $Locker:  $
00332 */
00333 

This is the CoreLinux++ reference manual
Provided by The CoreLinux Consortium