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
00104
static Int
getSemaphoreMaxValue(
SemaphoreGroupPtr, Int );
00105
00106
00107
00108
00117
static void groupDefined(
SemaphoreGroupPtr );
00118
00127
static Int
groupUnDefined(
SemaphoreGroupPtr );
00128
00139
static Int
setLock(
SemaphoreGroupPtr, Int, Int, Int );
00140
00151
static Int
setUnLock(
SemaphoreGroupPtr, Int, Int, Int );
00152
00163
static Int
waitZero(
SemaphoreGroupPtr, Int, Int, Int );
00164
00176
static Int
obtainSemaphore
00177 (
00178
SemaphoreGroupPtr,
00179 Int,
00180 IntRef,
00181 IntRef,
00182 IntRef,
00183 Int
00184 );
00185
00195
static Int
relinquishSemaphore(
SemaphoreGroupPtr,Int);
00196
00205
static Int
setMaxValue(
SemaphoreGroupPtr, Int, Int );
00206
00207
00208
00209
protected:
00210
00212
00213
SemaphoreCommon(
void );
00214
00216
00217
virtual ~SemaphoreCommon(
void );
00218
00219
00220
00221
00222
00229
void registerGroup(
SemaphoreGroupPtr );
00230
00237 Int
deregisterGroup(
SemaphoreGroupPtr );
00238
00250 Int
claimSemaphore
00251 (
00252
SemaphoreGroupPtr,
00253 Int,
00254 IntRef,
00255 IntRef,
00256 IntRef,
00257 Int
00258 );
00259
00268 Int
reclaimSemaphore(
SemaphoreGroupPtr,Int);
00269
00270
00272
00273
CSAGrpHeaderPtr findGroup
00274 (
00275 IntCref ,
00276 IntCref ,
00277
CSAGrpHeaderPtr
00278 );
00279
00281
00282
CSAGrpHeaderPtr findAvailableGroup
00283 (
00284 IntCref ,
00285 IntCref ,
00286
CSAGrpHeaderPtr
00287 );
00288
00290
00291
CSAGrpHeaderPtr subsetGroup( Int,
CSAGrpHeaderPtr ) ;
00292
00293
CSAGrpHeaderPtr combineGroup( Int,
CSAGrpHeaderPtr ) ;
00294
00295
bool isOriginator(
void )
const;
00296
00297 Int getOriginatorId(
void )
const;
00298
00299 Int canonicalUndefined(
void );
00300
00301
00303
00304
static void createAttachment(
void );
00305
00306
friend class CoreLinuxGuardPool;
00307
00309
00310
static void exitAttachment(
void );
00311
00312
00313
private:
00314
00315
SemaphoreCommon(
SemaphoreCommonCref )
00316
throw (
Assertion )
00317 :
00318
Synchronized()
00319 {
00320 NEVER_GET_HERE;
00321 }
00322
00323
private:
00324
00325 MemoryStoragePtr theCSA;
00326
CSAHeaderPtr theBase;
00327
bool theOriginator;
00328
static SemaphoreCommonPtr theInstance;
00329
static SemaphoreGroupPtr theControlGroup;
00330
static bool theInitializeFlag;
00331 };
00332
00333 }
00334
00335
#endif // if !defined(__SEMAPHORECOMMON_HPP)
00336
00337
00338
00339
00340
00341
00342
00343
00344