SemaphoreCommon.hpp
#if !defined(__SEMAPHORECOMMON_HPP)
#define __SEMAPHORECOMMON_HPP
/*
CoreLinux++
Copyright (C) 1999,2000 CoreLinux Consortium
The CoreLinux++ Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The CoreLinux++ Library Library is distributed in the hope that it will
be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#if !defined(__COMMON_HPP)
#include <Common.hpp>
#endif
namespace corelinux
{
struct _CSAHeader
{
Int creatorId; // 0 if not opened before
Int currentUsed; // The current used up in the pool
Int currentGrps; // The current groups present
Int reserved; //
};
DECLARE_TYPE( struct _CSAHeader, CSAHeader );
struct _CSAGroupHeader
{
Int groupInfo; // Either an Id, 0 if tail, or -1 if available
Int groupShares; // How many processes are using this
Int groupType; // -1 not used, 0 Mutex, 1 Gateway, 2-10 res
Int groupSemCount; // Semaphore count if info is -1
// and not reclaimed | !0
};
DECLARE_TYPE( struct _CSAGroupHeader, CSAGrpHeader );
struct _CSASemaphoreHeader
{
Int semOwner; // Current semaphore owner
Int maxSemValue; // 1 for mutexes, n for others, -1 if control
Word isRecursive; // ? for instance, 0 for control
Word isBalking; // ? for instance, 0 for control
Int semShares; // Shares for this semaphore
};
DECLARE_TYPE( struct _CSASemaphoreHeader, CSASemHeader );
DECLARE_CLASS( CoreLinuxGuardPool );
DECLARE_CLASS( SemaphoreGroup );
DECLARE_CLASS( MemoryStorage );
DECLARE_CLASS( SemaphoreCommon );
class SemaphoreCommon : public Synchronized
{
public:
//
// Accessors
//
static Int getSemaphoreMaxValue( SemaphoreGroupPtr, Int );
//
// Mutators
//
static void groupDefined( SemaphoreGroupPtr );
static Int groupUnDefined( SemaphoreGroupPtr );
static Int setLock( SemaphoreGroupPtr, Int, Int, Int );
static Int setUnLock( SemaphoreGroupPtr, Int, Int, Int );
static Int waitZero( SemaphoreGroupPtr, Int, Int, Int );
static Int obtainSemaphore
(
SemaphoreGroupPtr,
Int,
IntRef,
IntRef,
IntRef,
Int
);
static Int relinquishSemaphore(SemaphoreGroupPtr,Int);
static Int setMaxValue( SemaphoreGroupPtr, Int, Int );
protected:
SemaphoreCommon( void );
virtual ~SemaphoreCommon( void );
//
// Instance mutators
//
void registerGroup( SemaphoreGroupPtr );
Int deregisterGroup( SemaphoreGroupPtr );
Int claimSemaphore
(
SemaphoreGroupPtr,
Int,
IntRef,
IntRef,
IntRef,
Int
);
Int reclaimSemaphore(SemaphoreGroupPtr,Int);
CSAGrpHeaderPtr findGroup
(
IntCref ,
IntCref ,
CSAGrpHeaderPtr
);
CSAGrpHeaderPtr findAvailableGroup
(
IntCref ,
IntCref ,
CSAGrpHeaderPtr
);
CSAGrpHeaderPtr subsetGroup( Int, CSAGrpHeaderPtr ) ;
CSAGrpHeaderPtr combineGroup( Int, CSAGrpHeaderPtr ) ;
bool isOriginator( void ) const;
Int getOriginatorId( void ) const;
Int canonicalUndefined( void );
static void createAttachment( void );
friend class CoreLinuxGuardPool;
static void exitAttachment( void );
private:
SemaphoreCommon( SemaphoreCommonCref )
throw ( Assertion )
:
Synchronized()
{
NEVER_GET_HERE;
}
private:
MemoryStoragePtr theCSA;
CSAHeaderPtr theBase;
bool theOriginator;
static SemaphoreCommonPtr theInstance;
static SemaphoreGroupPtr theControlGroup;
static bool theInitializeFlag;
};
}
#endif // if !defined(__SEMAPHORECOMMON_HPP)
/*
Common rcs information do not modify
$Author: dulimart $
$Revision: 1.9 $
$Date: 2000/09/09 07:06:17 $
$Locker: $
*/
corelinux::SemaphoreCommon::groupUnDefined
static Int groupUnDefined(SemaphoreGroupPtr)
When the local process is deleting a semaphore group and it is considered a shared group...
Definition: SemaphoreCommon.cpp:884
corelinux::MemoryStorage
MemoryStorage is type of Storage characterized as transient and high speed.
Definition: MemoryStorage.hpp:47
corelinux::SemaphoreCommon::findGroup
CSAGrpHeaderPtr findGroup(IntCref, IntCref, CSAGrpHeaderPtr)
Attempt to locate a specific group.
Definition: SemaphoreCommon.cpp:657
corelinux::SemaphoreCommon::relinquishSemaphore
static Int relinquishSemaphore(SemaphoreGroupPtr, Int)
Called when the semaphore is no longer being referenced.
Definition: SemaphoreCommon.cpp:1054
corelinux::SemaphoreCommon::registerGroup
void registerGroup(SemaphoreGroupPtr)
Does the work of getting the group registered in the CSA.
Definition: SemaphoreCommon.cpp:253
corelinux::_CSASemaphoreHeader
Describes a CSA semaphore entry.
Definition: SemaphoreCommon.hpp:63
corelinux::SemaphoreCommon::reclaimSemaphore
Int reclaimSemaphore(SemaphoreGroupPtr, Int)
Called when a group wishes to let the CSA reclaim a semaphore share.
Definition: SemaphoreCommon.cpp:602
corelinux::SemaphoreCommon::waitZero
static Int waitZero(SemaphoreGroupPtr, Int, Int, Int)
Called by the base semaphore to wait for a specific semaphore to have a zero value.
Definition: SemaphoreCommon.cpp:979
corelinux::SemaphoreCommon::deregisterGroup
Int deregisterGroup(SemaphoreGroupPtr)
Does the work of reducing the group share count, or marking the group for reclaimation.
Definition: SemaphoreCommon.cpp:411
corelinux::SemaphoreCommon::subsetGroup
CSAGrpHeaderPtr subsetGroup(Int, CSAGrpHeaderPtr)
Utility to clean CSA group tail.
Definition: SemaphoreCommon.cpp:737
corelinux::CoreLinuxGuardPool
The CoreLinuxGuardPool is a private SemaphoreGroup resource for class objects that require synchroniz...
Definition: CoreLinuxGuardPool.hpp:97
corelinux::Synchronized::Synchronized
Synchronized(void)
Default constructor.
Definition: Synchronized.cpp:39
corelinux::SemaphoreCommon
The SemaphoreCommon manages the SemaphoreGroup common storage area.
Definition: SemaphoreCommon.hpp:89
corelinux::SemaphoreCommon::findAvailableGroup
CSAGrpHeaderPtr findAvailableGroup(IntCref, IntCref, CSAGrpHeaderPtr)
Find open slot that fits count criteria.
Definition: SemaphoreCommon.cpp:684
corelinux::_CSAGroupHeader
Describes a CSA semaphore group.
Definition: SemaphoreCommon.hpp:48
corelinux::SemaphoreCommon::exitAttachment
static void exitAttachment(void)
On the way out from run-time.
Definition: SemaphoreCommon.cpp:1155
corelinux::SemaphoreCommon::groupDefined
static void groupDefined(SemaphoreGroupPtr)
When a shared semaphore group is created, it is updated in the CSA, either by increasing the count of...
Definition: SemaphoreCommon.cpp:857
corelinux::SemaphoreCommon::setMaxValue
static Int setMaxValue(SemaphoreGroupPtr, Int, Int)
Called to set the semaphore maximum value.
Definition: SemaphoreCommon.cpp:1077
corelinux::SemaphoreCommon::setUnLock
static Int setUnLock(SemaphoreGroupPtr, Int, Int, Int)
Called by the base semaphore to relinquish a lock for a specific semaphore.
Definition: SemaphoreCommon.cpp:943
corelinux::Assertion
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
corelinux::Synchronized
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
corelinux::SemaphoreCommon::claimSemaphore
Int claimSemaphore(SemaphoreGroupPtr, Int, IntRef, IntRef, IntRef, Int)
Called when the group is determined to be shared and a semaphore share is to be claimed.
Definition: SemaphoreCommon.cpp:487
corelinux::SemaphoreCommon::obtainSemaphore
static Int obtainSemaphore(SemaphoreGroupPtr, Int, IntRef, IntRef, IntRef, Int)
Typically called by a SemaphoreGroup prior to passing out the semaphore type to the caller...
Definition: SemaphoreCommon.cpp:1016
corelinux::SemaphoreCommon::getSemaphoreMaxValue
static Int getSemaphoreMaxValue(SemaphoreGroupPtr, Int)
Returns the maximum value for a semaphore as defined by the original semaphore claimant.
Definition: SemaphoreCommon.cpp:1103
corelinux::_CSAHeader
Describes the tip control block for the Common Storage Area (CSA)
Definition: SemaphoreCommon.hpp:34
corelinux::SemaphoreCommon::~SemaphoreCommon
virtual ~SemaphoreCommon(void)
Destructor.
Definition: SemaphoreCommon.cpp:223
corelinux::SemaphoreCommon::setLock
static Int setLock(SemaphoreGroupPtr, Int, Int, Int)
Called by the base semaphore to aquire a lock for a specific semaphore.
Definition: SemaphoreCommon.cpp:905
corelinux::SemaphoreGroup
A SemaphoreGroup is an extension to the Linux semaphore set.
Definition: SemaphoreGroup.hpp:62
corelinux::SemaphoreCommon::SemaphoreCommon
SemaphoreCommon(void)
Default constructor used by class.
Definition: SemaphoreCommon.cpp:99
corelinux::SemaphoreCommon::createAttachment
static void createAttachment(void)
Factory for CSA.
Definition: SemaphoreCommon.cpp:1131

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