AbstractSemaphore.hpp
#if !defined(__ABSTRACTSEMAPHORE_HPP)
#define __ABSTRACTSEMAPHORE_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
#if !defined(__SEMAPHOREEXCEPTION_HPP)
#include <SemaphoreException.hpp>
#endif
namespace corelinux
{
enum SemaphoreOperationStatus
{
KERNELERROR=-1,
SUCCESS=0,
BALKED,
TIMEDOUT,
UNAVAILABLE
};
DECLARE_CLASS( SemaphoreGroup );
DECLARE_CLASS( AbstractSemaphore );
class AbstractSemaphore : public Synchronized
{
public:
//
// Constructors and destructors
//
AbstractSemaphore
(
SemaphoreGroupPtr,
SemaphoreIdentifierRef
)
throw ( NullPointerException );
virtual ~AbstractSemaphore( void );
//
// Operator overloads
//
bool operator==( AbstractSemaphoreCref aRef ) const;
//
// Accessors
//
virtual bool isBalkingEnabled( void ) const = 0;
virtual bool isRecursionEnabled( void ) const = 0;
SemaphoreIdentifierCref getIdentifier( void ) const ;
SemaphoreGroupIdentifierCref getGroupIdentifier( void ) const;
virtual ThreadIdentifierCref getOwningThreadIdentifier( void )
const = 0;
virtual CounterCref getRecursionQueueLength( void ) const = 0;
Int getValue( void );
Int getInitialValue( void );
virtual bool isLocked( void ) = 0;
//
// Mutators
//
virtual SemaphoreOperationStatus lockWithWait( void )
throw(SemaphoreException) = 0;
virtual SemaphoreOperationStatus lockWithNoWait( void )
throw(SemaphoreException) = 0;
// virtual SemaphoreOperationStatus lockWithTimeOut( Timer )
// throw(SemaphoreException) = 0;
virtual SemaphoreOperationStatus release( void )
throw(SemaphoreException) = 0;
protected:
//
// Constructors
//
AbstractSemaphore( AbstractSemaphoreCref )
throw(Assertion);
//
// Operator overloads
//
AbstractSemaphoreRef operator=( AbstractSemaphoreCref )
throw(Assertion);
//
// Accessors
//
inline SemaphoreIdentifierRef getId( void )
{
return theSemIdentifier;
}
inline Int getGroupId( void ) const
{
return theGroupIdentifier;
}
virtual ThreadIdentifierRef getOwnerId( void ) = 0;
//
// Mutators
//
SemaphoreOperationStatus setLock( Int );
SemaphoreOperationStatus setUnlock( Int );
SemaphoreOperationStatus waitZero( Int );
SemaphoreOperationStatus setValue( Int );
private:
SemaphoreGroupPtr theGroup;
Int theGroupIdentifier;
SemaphoreIdentifier theSemIdentifier;
};
}
#endif // if !defined(__ABSTRACTSEMAPHORE_HPP)
/*
Common rcs information do not modify
$Author: dulimart $
$Revision: 1.5 $
$Date: 2000/09/09 06:54:53 $
$Locker: $
*/
corelinux::KERNELERROR
Kernel error, errno set.
Definition: AbstractSemaphore.hpp:43
corelinux::TIMEDOUT
Semaphore request timed out.
Definition: AbstractSemaphore.hpp:55
corelinux::AbstractSemaphore::getInitialValue
Int getInitialValue(void)
Retrieves the initial value for a semaphore.
Definition: AbstractSemaphore.cpp:120
corelinux::BALKED
Semaphore balked request.
Definition: AbstractSemaphore.hpp:51
corelinux::AbstractSemaphore::AbstractSemaphore
AbstractSemaphore(SemaphoreGroupPtr, SemaphoreIdentifierRef)
Default constructor.
Definition: AbstractSemaphore.cpp:64
corelinux::UNAVAILABLE
Semaphore unavailable for request.
Definition: AbstractSemaphore.hpp:59
corelinux::AbstractSemaphore::getId
SemaphoreIdentifierRef getId(void)
Returns a reference to the AbstractSemaphore identifier.
Definition: AbstractSemaphore.hpp:205
corelinux::AbstractSemaphore::getRecursionQueueLength
virtual CounterCref getRecursionQueueLength(void) const =0
Return the depth of the recursion for the owner.
corelinux::SUCCESS
Call success.
Definition: AbstractSemaphore.hpp:47
corelinux::AbstractSemaphore::isRecursionEnabled
virtual bool isRecursionEnabled(void) const =0
Returns true if recursion allowed.
corelinux::AbstractSemaphore::getGroupId
Int getGroupId(void) const
Returns a reference to the group identifier.
Definition: AbstractSemaphore.hpp:213
corelinux::AbstractSemaphore::setLock
SemaphoreOperationStatus setLock(Int)
Calls kernel lock mechanism.
Definition: AbstractSemaphore.cpp:147
corelinux::SemaphoreOperationStatus
SemaphoreOperationStatus
Semaphore method return enumeration.
Definition: AbstractSemaphore.hpp:39
corelinux::AbstractSemaphore::getOwningThreadIdentifier
virtual ThreadIdentifierCref getOwningThreadIdentifier(void) const =0
Returns the identifier of who currently owns the semaphore.
corelinux::AbstractSemaphore::setUnlock
SemaphoreOperationStatus setUnlock(Int)
Calls kernel unlock mechanism.
Definition: AbstractSemaphore.cpp:167
corelinux
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
corelinux::AbstractSemaphore::operator==
bool operator==(AbstractSemaphoreCref aRef) const
Equality operator returns true if identifiers match.
corelinux::NullPointerException
NullPointerException is the base exception type for NullPointer.
Definition: NullPointerException.hpp:40
corelinux::AbstractSemaphore::release
virtual SemaphoreOperationStatus release(void)=0
Request the AbstractSemaphore but timeout if not available.
corelinux::ScalarIdentifier
ScalarIdentifier provides a templated interface for declaring CoreLinux Identifiers for simple scalar...
Definition: ScalarIdentifiers.hpp:37
corelinux::AbstractSemaphore
A AbstractSemaphore supports the protocol that processes and/or threads agree to follow for the purpo...
Definition: AbstractSemaphore.hpp:85
corelinux::AbstractSemaphore::getIdentifier
SemaphoreIdentifierCref getIdentifier(void) const
Return a reference to this AbstractSemaphore identifier.
Definition: AbstractSemaphore.cpp:113
corelinux::AbstractSemaphore::getOwnerId
virtual ThreadIdentifierRef getOwnerId(void)=0
Returns a reference to the owning thread.
corelinux::SemaphoreException
SemaphoreException is the base exception type for Semaphore.
Definition: SemaphoreException.hpp:39
corelinux::AbstractSemaphore::isLocked
virtual bool isLocked(void)=0
Ask if AbstractSemaphore instance is locked.
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::AbstractSemaphore::getGroupIdentifier
SemaphoreGroupIdentifierCref getGroupIdentifier(void) const
Returns a reference to the SemaphoreGroup identifier.
Definition: AbstractSemaphore.cpp:108
corelinux::AbstractSemaphore::getValue
Int getValue(void)
Returns the current value of the semaphore.
Definition: AbstractSemaphore.cpp:130
corelinux::AbstractSemaphore::isBalkingEnabled
virtual bool isBalkingEnabled(void) const =0
Returns true if balking enabled.
corelinux::AbstractSemaphore::~AbstractSemaphore
virtual ~AbstractSemaphore(void)
Virtual Destructor.
Definition: AbstractSemaphore.cpp:101
corelinux::AbstractSemaphore::waitZero
SemaphoreOperationStatus waitZero(Int)
Calls kernel zero mechanism.
Definition: AbstractSemaphore.cpp:184
corelinux::AbstractSemaphore::setValue
SemaphoreOperationStatus setValue(Int)
Sets the value for the AbstractSemaphore.
Definition: AbstractSemaphore.cpp:200
corelinux::AbstractSemaphore::lockWithWait
virtual SemaphoreOperationStatus lockWithWait(void)=0
Request the lock, wait for availability.
corelinux::SemaphoreGroup
A SemaphoreGroup is an extension to the Linux semaphore set.
Definition: SemaphoreGroup.hpp:62
corelinux::AbstractSemaphore::lockWithNoWait
virtual SemaphoreOperationStatus lockWithNoWait(void)=0
Request the lock without waiting.

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