CoreLinux++  0.4.32
SemaphoreCommon.hpp
1 #if !defined(__SEMAPHORECOMMON_HPP)
2 #define __SEMAPHORECOMMON_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 namespace corelinux
29 {
34  struct _CSAHeader
35  {
36  Int creatorId; // 0 if not opened before
37  Int currentUsed; // The current used up in the pool
38  Int currentGrps; // The current groups present
39  Int reserved; //
40  };
41 
42  DECLARE_TYPE( struct _CSAHeader, CSAHeader );
43 
49  {
50  Int groupInfo; // Either an Id, 0 if tail, or -1 if available
51  Int groupShares; // How many processes are using this
52  Int groupType; // -1 not used, 0 Mutex, 1 Gateway, 2-10 res
53  Int groupSemCount; // Semaphore count if info is -1
54  // and not reclaimed | !0
55  };
56 
57  DECLARE_TYPE( struct _CSAGroupHeader, CSAGrpHeader );
58 
64  {
65  Int semOwner; // Current semaphore owner
66  Int maxSemValue; // 1 for mutexes, n for others, -1 if control
67  Word isRecursive; // ? for instance, 0 for control
68  Word isBalking; // ? for instance, 0 for control
69  Int semShares; // Shares for this semaphore
70  };
71 
72  DECLARE_TYPE( struct _CSASemaphoreHeader, CSASemHeader );
73 
74  DECLARE_CLASS( CoreLinuxGuardPool );
75 
76  DECLARE_CLASS( SemaphoreGroup );
77 
78  DECLARE_CLASS( MemoryStorage );
79 
80  DECLARE_CLASS( SemaphoreCommon );
81 
90  {
91  public:
92 
93  //
94  // Accessors
95  //
96 
104  static Int getSemaphoreMaxValue( SemaphoreGroupPtr, Int );
105 
106  //
107  // Mutators
108  //
117  static void groupDefined( SemaphoreGroupPtr );
118 
127  static Int groupUnDefined( SemaphoreGroupPtr );
128 
139  static Int setLock( SemaphoreGroupPtr, Int, Int, Int );
140 
151  static Int setUnLock( SemaphoreGroupPtr, Int, Int, Int );
152 
163  static Int waitZero( SemaphoreGroupPtr, Int, Int, Int );
164 
176  static Int obtainSemaphore
177  (
179  Int,
180  IntRef,
181  IntRef,
182  IntRef,
183  Int
184  );
185 
195  static Int relinquishSemaphore(SemaphoreGroupPtr,Int);
196 
205  static Int setMaxValue( SemaphoreGroupPtr, Int, Int );
206 
207 
208 
209  protected:
210 
212 
213  SemaphoreCommon( void );
214 
216 
217  virtual ~SemaphoreCommon( void );
218 
219  //
220  // Instance mutators
221  //
222 
229  void registerGroup( SemaphoreGroupPtr );
230 
237  Int deregisterGroup( SemaphoreGroupPtr );
238 
250  Int claimSemaphore
251  (
253  Int,
254  IntRef,
255  IntRef,
256  IntRef,
257  Int
258  );
259 
268  Int reclaimSemaphore(SemaphoreGroupPtr,Int);
269 
270 
272 
273  CSAGrpHeaderPtr findGroup
274  (
275  IntCref ,
276  IntCref ,
278  );
279 
281 
282  CSAGrpHeaderPtr findAvailableGroup
283  (
284  IntCref ,
285  IntCref ,
287  );
288 
290 
291  CSAGrpHeaderPtr subsetGroup( Int, CSAGrpHeaderPtr ) ;
292 
293  CSAGrpHeaderPtr combineGroup( Int, CSAGrpHeaderPtr ) ;
294 
295  bool isOriginator( void ) const;
296 
297  Int getOriginatorId( void ) const;
298 
299  Int canonicalUndefined( void );
300 
301 
303 
304  static void createAttachment( void );
305 
306  friend class CoreLinuxGuardPool;
307 
309 
310  static void exitAttachment( void );
311 
312 
313  private:
314 
316  throw ( Assertion )
317  :
318  Synchronized()
319  {
320  NEVER_GET_HERE;
321  }
322 
323  private:
324 
325  MemoryStoragePtr theCSA;
326  CSAHeaderPtr theBase;
327  bool theOriginator;
328  static SemaphoreCommonPtr theInstance;
329  static SemaphoreGroupPtr theControlGroup;
330  static bool theInitializeFlag;
331  };
332 
333 }
334 
335 #endif // if !defined(__SEMAPHORECOMMON_HPP)
336 
337 /*
338  Common rcs information do not modify
339  $Author: dulimart $
340  $Revision: 1.9 $
341  $Date: 2000/09/09 07:06:17 $
342  $Locker: $
343 */
344 
MemoryStorage is type of Storage characterized as transient and high speed.
Definition: MemoryStorage.hpp:47
Describes a CSA semaphore entry.
Definition: SemaphoreCommon.hpp:63
The CoreLinuxGuardPool is a private SemaphoreGroup resource for class objects that require synchroniz...
Definition: CoreLinuxGuardPool.hpp:97
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
The SemaphoreCommon manages the SemaphoreGroup common storage area.
Definition: SemaphoreCommon.hpp:89
Describes a CSA semaphore group.
Definition: SemaphoreCommon.hpp:48
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
Describes the tip control block for the Common Storage Area (CSA)
Definition: SemaphoreCommon.hpp:34
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