CoreLinux++  0.4.32
Semaphore.hpp
1 #if !defined(__SEMAPHORE_HPP)
2 #define __SEMAPHORE_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(__ABSTRACTSEMAPHORE_HPP)
29 #include <AbstractSemaphore.hpp>
30 #endif
31 
32 #if !defined(__SEMAPHOREEXCEPTION_HPP)
33 #include <SemaphoreException.hpp>
34 #endif
35 
36 namespace corelinux
37 {
38 
39  DECLARE_CLASS( Semaphore );
40 
62  {
63 
64  public:
65 
66 
67  //
68  // Constructors and destructors
69  //
70 
82  Semaphore
83  (
86  bool Recursive=false,
87  bool Balking=false
88  ) throw ( NullPointerException );
89 
91 
92  virtual ~Semaphore( void );
93 
94  //
95  // Operator overloads
96  //
97 
99 
100  bool operator==( SemaphoreCref aRef ) const;
101 
102  //
103  // Accessors
104  //
105 
107 
108  virtual bool isBalkingEnabled( void ) const;
109 
111 
112  virtual bool isRecursionEnabled( void ) const;
113 
115 
116  virtual ThreadIdentifierCref getOwningThreadIdentifier( void ) const;
117 
119 
120  virtual CounterCref getRecursionQueueLength( void ) const;
121 
122 
123  protected:
124 
125  //
126  // Constructors
127  //
128 
130 
131  Semaphore( void )
132  throw(Assertion);
133 
135 
137  throw(Assertion);
138 
139  //
140  // Operator overloads
141  //
143 
145  throw(Assertion);
146 
148 
149  CounterCref operator++( void );
150 
152 
153  CounterCref operator--( void );
154 
155  //
156  // Accessors
157  //
158 
160 
161  virtual ThreadIdentifierRef getOwnerId( void );
162 
163  //
164  // Mutators
165  //
166 
168 
169  virtual void setOwnerId( void );
170 
172 
173  virtual void setRecursionQueueLength( Counter );
174 
176 
177  virtual void resetOwnerId( void );
178 
179 
180  private:
181 
183 
184  ThreadIdentifier theOwningThread;
185 
187 
188  Counter theRecursionQueueLength;
189 
191 
192  bool theRecursiveMode;
193 
195 
196  bool theBalkingMode;
197 
198  };
199 }
200 
201 #endif // if !defined(__SEMAPHORE_HPP)
202 
203 /*
204  Common rcs information do not modify
205  $Author: frankc $
206  $Revision: 1.2 $
207  $Date: 2000/06/02 11:51:52 $
208  $Locker: $
209 */
210 
virtual CounterCref getRecursionQueueLength(void) const
Return the depth of the recursion for the owner.
Definition: Semaphore.cpp:153
CounterCref operator++(void)
Operator for increasing theRecursionQueueLength.
Definition: Semaphore.cpp:118
virtual ~Semaphore(void)
Virtual Destructor.
Definition: Semaphore.cpp:90
virtual ThreadIdentifierRef getOwnerId(void)
Returns a reference to the owning thread.
Definition: Semaphore.cpp:160
virtual void setRecursionQueueLength(Counter)
Sets the recursion length.
Definition: Semaphore.cpp:174
SemaphoreRef operator=(SemaphoreCref)
Assignment operator throws assertion.
Definition: Semaphore.cpp:110
virtual ThreadIdentifierCref getOwningThreadIdentifier(void) const
Returns the identifier of who currently owns the semaphore.
Definition: Semaphore.cpp:146
Semaphore(SemaphoreGroupPtr, SemaphoreIdentifierRef, bool Recursive=false, bool Balking=false)
Default constructor requires the identifier of the semaphore in the semaphore group.
Definition: Semaphore.cpp:43
NullPointerException is the base exception type for NullPointer.
Definition: NullPointerException.hpp:40
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
bool operator==(SemaphoreCref aRef) const
Equality operator returns true if identifiers match.
Definition: Semaphore.cpp:100
A Semaphore supports the protocol that processes and/or threads agree to follow for the purpose of co...
Definition: Semaphore.hpp:61
Assertion is-a Exception created when an assertion fails.
Definition: Assertion.hpp:423
CounterCref operator--(void)
Operator for decreasing theRecursionQueueLength.
Definition: Semaphore.cpp:125
virtual void resetOwnerId(void)
Sets the owner thread id to not owned.
Definition: Semaphore.cpp:181
virtual void setOwnerId(void)
Sets the owner id to the current thread.
Definition: Semaphore.cpp:167
virtual bool isRecursionEnabled(void) const
Returns true if recursion allowed.
Definition: Semaphore.cpp:139
virtual bool isBalkingEnabled(void) const
Returns true if balking enabled.
Definition: Semaphore.cpp:132
A SemaphoreGroup is an extension to the Linux semaphore set.
Definition: SemaphoreGroup.hpp:62

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