1 -- Created on: 1992-04-21
2 -- Created by: Stephan GARNAUD (ARM)
3 -- Copyright (c) 1992-1999 Matra Datavision
4 -- Copyright (c) 1999-2012 OPEN CASCADE SAS
6 -- The content of this file is subject to the Open CASCADE Technology Public
7 -- License Version 6.5 (the "License"). You may not use the content of this file
8 -- except in compliance with the License. Please obtain a copy of the License
9 -- at http://www.opencascade.org and read it completely before using this file.
11 -- The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
12 -- main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
14 -- The Original Code and all software distributed under the License is
15 -- distributed on an "AS IS" basis, without warranty of any kind, and the
16 -- Initial Developer hereby disclaims all such warranties, including without
17 -- limitation, any warranties of merchantability, fitness for a particular
18 -- purpose or non-infringement. Please see the License for the specific terms
19 -- and conditions governing the rights and limitations under the License.
26 class Semaphore from OSD
28 ---Purpose: IPC Tools -Semaphores
29 -- The semaphores are used to facilitate shared resources.
30 -- This implementation provides a way to ensure mutual
31 -- exclusion using 'Lock' and 'Free' primitives.
32 -- The Lock is used to prevent access if it's not yet allowed.
33 -- The Free validates the semaphores and if possible, frees process
34 -- waiting for a common resource.
36 uses Protection, Error, AsciiString from TCollection
37 raises ConstructionError, OSDError, ProgramError
41 Create returns Semaphore;
42 ---Purpose: Allocate room for semaphore name.
43 -- This is to be used with 'Open'.
44 -- so the process is a client.
47 Create (Name : AsciiString) returns Semaphore
48 ---Purpose: Instantiates Semaphore object with a name.
49 -- The name is the only way provided to work with a common
50 -- semaphore for different processes.
51 -- Each process working with the same semaphore must use
52 -- a common known access : the semaphore's NAME.
53 -- Raises ConstructionError when the name contains characters
54 -- not in range of ' '...'~'.
55 -- This is for a server process.
57 raises ConstructionError;
59 Build (me : in out) is static;
60 ---Purpose: Sets semaphore (physically) into memory
63 Open (me : in out ; Name : AsciiString)
64 ---Purpose: Opens (physically) a semaphore
65 -- Raises ConstructionError when the name contains characters
66 -- not in range of ' '...'~'.
68 raises ConstructionError is static;
70 GetCounter (me : in out) returns Integer is static;
71 ---Purpose: Returns current value of the semaphore's counter.
72 -- Raises ProgramError when the semaphore is not open.
75 SetCounter (me : in out; Value : Integer) is static;
76 ---Purpose: Sets the semaphore's counter to a specific value.
77 -- Raises ProgramError when the semaphore is not open.
81 ---Purpose: Removes the semaphore.
82 -- This is used only by server process !
83 -- Raise ProgramError if the semaphore is already deleted.
85 raises ProgramError is static;
88 ---Purpose: Makes current process waiting for access
89 -- Raises ProgramError when the semaphore does't exist.
91 raises ProgramError is static;
94 ---Purpose: Frees one access to a semaphore.
95 -- Raises ProgramError when the semaphore does't exist.
97 raises ProgramError is static;
100 ---Purpose: Resets semaphore counter to zero.
101 -- Raises ProgramError when the semaphore does't exist.
103 raises ProgramError is static;
105 Failed (me) returns Boolean is static;
106 ---Purpose: Returns TRUE if an error occurs
109 Reset (me : in out) is static;
110 ---Purpose: Resets error counter to zero
114 ---Purpose: Raises OSD_Error
116 raises OSDError is static;
118 Error (me) returns Integer is static;
119 ---Purpose: Returns error number if 'Failed' is TRUE.
123 myName : AsciiString; -- The semaphore name
125 mySemId : Integer; -- Internal identification of semaphore
127 end Semaphore from OSD;