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 
230 
238 
250  Int claimSemaphore
251  (
253  Int,
254  IntRef,
255  IntRef,
256  IntRef,
257  Int
258  );
259 
269 
270 
272 
274  (
275  IntCref ,
276  IntCref ,
278  );
279 
281 
283  (
284  IntCref ,
285  IntCref ,
287  );
288 
290 
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 
static Int groupUnDefined(SemaphoreGroupPtr)
When the local process is deleting a semaphore group and it is considered a shared group...
Definition: SemaphoreCommon.cpp:884
MemoryStorage is type of Storage characterized as transient and high speed.
Definition: MemoryStorage.hpp:47
CSAGrpHeaderPtr findGroup(IntCref, IntCref, CSAGrpHeaderPtr)
Attempt to locate a specific group.
Definition: SemaphoreCommon.cpp:657
static Int relinquishSemaphore(SemaphoreGroupPtr, Int)
Called when the semaphore is no longer being referenced.
Definition: SemaphoreCommon.cpp:1054
void registerGroup(SemaphoreGroupPtr)
Does the work of getting the group registered in the CSA.
Definition: SemaphoreCommon.cpp:253
Describes a CSA semaphore entry.
Definition: SemaphoreCommon.hpp:63
Int reclaimSemaphore(SemaphoreGroupPtr, Int)
Called when a group wishes to let the CSA reclaim a semaphore share.
Definition: SemaphoreCommon.cpp:602
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
Int deregisterGroup(SemaphoreGroupPtr)
Does the work of reducing the group share count, or marking the group for reclaimation.
Definition: SemaphoreCommon.cpp:411
CSAGrpHeaderPtr subsetGroup(Int, CSAGrpHeaderPtr)
Utility to clean CSA group tail.
Definition: SemaphoreCommon.cpp:737
The CoreLinuxGuardPool is a private SemaphoreGroup resource for class objects that require synchroniz...
Definition: CoreLinuxGuardPool.hpp:97
Synchronized(void)
Default constructor.
Definition: Synchronized.cpp:39
Forward reference the various common classes.
Definition: AbstractAllocator.hpp:32
The SemaphoreCommon manages the SemaphoreGroup common storage area.
Definition: SemaphoreCommon.hpp:89
CSAGrpHeaderPtr findAvailableGroup(IntCref, IntCref, CSAGrpHeaderPtr)
Find open slot that fits count criteria.
Definition: SemaphoreCommon.cpp:684
Describes a CSA semaphore group.
Definition: SemaphoreCommon.hpp:48
static void exitAttachment(void)
On the way out from run-time.
Definition: SemaphoreCommon.cpp:1155
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
static Int setMaxValue(SemaphoreGroupPtr, Int, Int)
Called to set the semaphore maximum value.
Definition: SemaphoreCommon.cpp:1077
static Int setUnLock(SemaphoreGroupPtr, Int, Int, Int)
Called by the base semaphore to relinquish a lock for a specific semaphore.
Definition: SemaphoreCommon.cpp:943
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
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
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
static Int getSemaphoreMaxValue(SemaphoreGroupPtr, Int)
Returns the maximum value for a semaphore as defined by the original semaphore claimant.
Definition: SemaphoreCommon.cpp:1103
Describes the tip control block for the Common Storage Area (CSA)
Definition: SemaphoreCommon.hpp:34
virtual ~SemaphoreCommon(void)
Destructor.
Definition: SemaphoreCommon.cpp:223
static Int setLock(SemaphoreGroupPtr, Int, Int, Int)
Called by the base semaphore to aquire a lock for a specific semaphore.
Definition: SemaphoreCommon.cpp:905
A SemaphoreGroup is an extension to the Linux semaphore set.
Definition: SemaphoreGroup.hpp:62
SemaphoreCommon(void)
Default constructor used by class.
Definition: SemaphoreCommon.cpp:99
static void createAttachment(void)
Factory for CSA.
Definition: SemaphoreCommon.cpp:1131

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