CoreLinux++  0.4.32
AbstractSemaphore.hpp
1 #if !defined(__ABSTRACTSEMAPHORE_HPP)
2 #define __ABSTRACTSEMAPHORE_HPP
3 
4 /*
5  CoreLinux++
6  Copyright (C) 1999,2000 CoreLinux Consortium
7 
8  The CoreLinux++ Library is free software; you can redistribute it and/or
9  modify it under the terms of the GNU Library General Public License as
10  published by the Free Software Foundation; either version 2 of the
11  License, or (at your option) any later version.
12 
13  The CoreLinux++ Library Library is distributed in the hope that it will
14  be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  Library General Public License for more details.
17 
18  You should have received a copy of the GNU Library General Public
19  License along with the GNU C Library; see the file COPYING.LIB. If not,
20  write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA 02111-1307, USA.
22 */
23 
24 #if !defined(__COMMON_HPP)
25 #include <Common.hpp>
26 #endif
27 
28 #if !defined(__SEMAPHOREEXCEPTION_HPP)
29 #include <SemaphoreException.hpp>
30 #endif
31 
32 namespace corelinux
33 {
34 
40  {
42 
44 
46 
48 
50 
52 
54 
56 
58 
60  };
61 
62  DECLARE_CLASS( SemaphoreGroup );
63  DECLARE_CLASS( AbstractSemaphore );
64 
86  {
87 
88  public:
89 
90 
91  //
92  // Constructors and destructors
93  //
94 
100  (
103  )
104  throw ( NullPointerException );
105 
107 
108  virtual ~AbstractSemaphore( void );
109 
110  //
111  // Operator overloads
112  //
114 
115  bool operator==( AbstractSemaphoreCref aRef ) const;
116 
117  //
118  // Accessors
119  //
120 
122 
123  virtual bool isBalkingEnabled( void ) const = 0;
124 
126 
127  virtual bool isRecursionEnabled( void ) const = 0;
128 
130 
131  SemaphoreIdentifierCref getIdentifier( void ) const ;
132 
134 
136 
138 
139  virtual ThreadIdentifierCref getOwningThreadIdentifier( void )
140  const = 0;
141 
143 
144  virtual CounterCref getRecursionQueueLength( void ) const = 0;
145 
147 
148  Int getValue( void );
149 
151 
152  Int getInitialValue( void );
153 
155 
156  virtual bool isLocked( void ) = 0;
157 
158 
159  //
160  // Mutators
161  //
162 
164 
165  virtual SemaphoreOperationStatus lockWithWait( void )
166  throw(SemaphoreException) = 0;
167 
169 
171  throw(SemaphoreException) = 0;
172 
174 
175 // virtual SemaphoreOperationStatus lockWithTimeOut( Timer )
176 // throw(SemaphoreException) = 0;
177 
179 
180  virtual SemaphoreOperationStatus release( void )
181  throw(SemaphoreException) = 0;
182 
183 
184  protected:
185 
186  //
187  // Constructors
188  //
189 
191  throw(Assertion);
192 
193  //
194  // Operator overloads
195  //
197  throw(Assertion);
198 
199  //
200  // Accessors
201  //
202 
204 
206  {
207  return theSemIdentifier;
208  }
209 
210 
212 
213  inline Int getGroupId( void ) const
214  {
215  return theGroupIdentifier;
216  }
217 
219 
220  virtual ThreadIdentifierRef getOwnerId( void ) = 0;
221 
222 
223 
224  //
225  // Mutators
226  //
228 
230 
232 
234 
236 
238 
240 
242 
243 
244  private:
245 
247 
248  SemaphoreGroupPtr theGroup;
249 
251 
252  Int theGroupIdentifier;
253 
255 
256  SemaphoreIdentifier theSemIdentifier;
257 
258  };
259 }
260 
261 #endif // if !defined(__ABSTRACTSEMAPHORE_HPP)
262 
263 /*
264  Common rcs information do not modify
265  $Author: dulimart $
266  $Revision: 1.5 $
267  $Date: 2000/09/09 06:54:53 $
268  $Locker: $
269 */
270 
271 
272 
273 
Kernel error, errno set.
Definition: AbstractSemaphore.hpp:43
Semaphore request timed out.
Definition: AbstractSemaphore.hpp:55
Int getInitialValue(void)
Retrieves the initial value for a semaphore.
Definition: AbstractSemaphore.cpp:120
Semaphore balked request.
Definition: AbstractSemaphore.hpp:51
AbstractSemaphore(SemaphoreGroupPtr, SemaphoreIdentifierRef)
Default constructor.
Definition: AbstractSemaphore.cpp:64
Semaphore unavailable for request.
Definition: AbstractSemaphore.hpp:59
SemaphoreIdentifierRef getId(void)
Returns a reference to the AbstractSemaphore identifier.
Definition: AbstractSemaphore.hpp:205
virtual CounterCref getRecursionQueueLength(void) const =0
Return the depth of the recursion for the owner.
Call success.
Definition: AbstractSemaphore.hpp:47
virtual bool isRecursionEnabled(void) const =0
Returns true if recursion allowed.
Int getGroupId(void) const
Returns a reference to the group identifier.
Definition: AbstractSemaphore.hpp:213
SemaphoreOperationStatus setLock(Int)
Calls kernel lock mechanism.
Definition: AbstractSemaphore.cpp:147
SemaphoreOperationStatus
Semaphore method return enumeration.
Definition: AbstractSemaphore.hpp:39
virtual ThreadIdentifierCref getOwningThreadIdentifier(void) const =0
Returns the identifier of who currently owns the semaphore.
SemaphoreOperationStatus setUnlock(Int)
Calls kernel unlock mechanism.
Definition: AbstractSemaphore.cpp:167
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
bool operator==(AbstractSemaphoreCref aRef) const
Equality operator returns true if identifiers match.
NullPointerException is the base exception type for NullPointer.
Definition: NullPointerException.hpp:40
virtual SemaphoreOperationStatus release(void)=0
Request the AbstractSemaphore but timeout if not available.
ScalarIdentifier provides a templated interface for declaring CoreLinux Identifiers for simple scalar...
Definition: ScalarIdentifiers.hpp:37
A AbstractSemaphore supports the protocol that processes and/or threads agree to follow for the purpo...
Definition: AbstractSemaphore.hpp:85
SemaphoreIdentifierCref getIdentifier(void) const
Return a reference to this AbstractSemaphore identifier.
Definition: AbstractSemaphore.cpp:113
virtual ThreadIdentifierRef getOwnerId(void)=0
Returns a reference to the owning thread.
SemaphoreException is the base exception type for Semaphore.
Definition: SemaphoreException.hpp:39
virtual bool isLocked(void)=0
Ask if AbstractSemaphore instance is locked.
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
Synchronized is a mixin which allows class objects to enable monitor functionality.
Definition: Synchronized.hpp:41
SemaphoreGroupIdentifierCref getGroupIdentifier(void) const
Returns a reference to the SemaphoreGroup identifier.
Definition: AbstractSemaphore.cpp:108
Int getValue(void)
Returns the current value of the semaphore.
Definition: AbstractSemaphore.cpp:130
virtual bool isBalkingEnabled(void) const =0
Returns true if balking enabled.
virtual ~AbstractSemaphore(void)
Virtual Destructor.
Definition: AbstractSemaphore.cpp:101
SemaphoreOperationStatus waitZero(Int)
Calls kernel zero mechanism.
Definition: AbstractSemaphore.cpp:184
SemaphoreOperationStatus setValue(Int)
Sets the value for the AbstractSemaphore.
Definition: AbstractSemaphore.cpp:200
virtual SemaphoreOperationStatus lockWithWait(void)=0
Request the lock, wait for availability.
A SemaphoreGroup is an extension to the Linux semaphore set.
Definition: SemaphoreGroup.hpp:62
virtual SemaphoreOperationStatus lockWithNoWait(void)=0
Request the lock without waiting.

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