2 Copyright (c) 1998-1999 Matra Datavision
3 Copyright (c) 1999-2012 OPEN CASCADE SAS
5 The content of this file is subject to the Open CASCADE Technology Public
6 License Version 6.5 (the "License"). You may not use the content of this file
7 except in compliance with the License. Please obtain a copy of the License
8 at http://www.opencascade.org and read it completely before using this file.
10 The Initial Developer of the Original Code is Open CASCADE S.A.S., having its
11 main offices at: 1, place des Freres Montgolfier, 78280 Guyancourt, France.
13 The Original Code and all software distributed under the License is
14 distributed on an "AS IS" basis, without warranty of any kind, and the
15 Initial Developer hereby disclaims all such warranties, including without
16 limitation, any warranties of merchantability, fitness for a particular
17 purpose or non-infringement. Please see the License for the specific terms
18 and conditions governing the rights and limitations under the License.
31 #ifdef HAVE_SYS_TYPES_H
32 # include <sys/types.h>
51 /* Modified by Stephan GARNAUD (ARM) 1992 for Matra Datavision */
53 #if (!defined (__hpux)) && (!defined (HPUX))
55 #define CLUSTER_NUMBER 4
56 #define SIGUSER SIGUSR1-1
58 static struct sembuf event_flag ;
60 static void osd_signal_(int);
61 int osd_getkey(char *);
63 int create_semaphore(char *);
64 int open_semaphore(char *);
65 int lock_semaphore(int *,int *);
66 int free_semaphore(int *,int *);
67 int reset_semaphore(int *,int *);
68 int remove_semaphore(int *,char *);
69 int osd_signl_(int *);
70 int osd_skill_(int *,int *);
71 int osd_alarm_(int,void (*)());
82 create_semaphore(char *name)
83 /*=======================================================
85 CREATE a semaphore cluster of 32 events
87 =========================================================*/
96 key = (key_t) osd_getkey (name);
99 status = semget(key,CLUSTER_NUMBER,0750 + IPC_CREAT) ;
101 if( status < 0 ) return (0) ; /* semget failed */
107 open_semaphore(char *name)
108 /*=========================================================
110 OPEN a semaphore cluster
112 =========================================================================*/
120 key = (key_t) osd_getkey (name);
121 status = semget(key,0,0) ;
123 if( status < 0 ) return (0) ; /* semget failed */
130 lock_semaphore(int *semid, int *event)
131 /*==================================================
133 WAIT & LOCK the semaphore attached to the cluster
135 ====================================================*/
139 event_flag.sem_num = *event ;
140 event_flag.sem_op = -1 ;
141 event_flag.sem_flg = SEM_UNDO;
144 #if defined(SEMOP_NO_REFERENCE) && !defined(DECOSF1)
145 status = semop(*semid,event_flag,1) ;
147 status = semop(*semid,&event_flag,1) ;
149 while ( status < 0 && errno != EINTR );
159 free_semaphore(int *semid, int *event)
160 /*==================================================
162 FREE the semaphore attached to the cluster
164 ====================================================*/
169 event_flag.sem_num = *event ;
170 event_flag.sem_op = 1 ;
171 event_flag.sem_flg = IPC_NOWAIT ;
173 #ifdef SEMCTL_NO_REFERENCE
174 status = semctl(*semid,*event,GETVAL,zero_value);
176 status = semctl(*semid,*event,GETVAL,&zero_value);
179 #if defined(SEMOP_NO_REFERENCE) && !defined(DECOSF1)
180 status = semop(*semid,event_flag,1) ;
182 status = semop(*semid,&event_flag,1) ;
195 reset_semaphore(int *semid, int *event)
196 /*===================================================
198 RESET semaphore to initial state
200 ======================================================*/
205 #ifdef SEMCTL_NO_REFERENCE
206 status = semctl(*semid,*event,SETVAL,zero_value);
208 status = semctl(*semid,*event,SETVAL,&zero_value);
210 if (status < 0) return(0);
217 set_semaphore(int *semid, int *event, int value)
218 /*=================================================
220 SET semaphore counter to a fixed value
222 ====================================================*/
226 #ifdef SEMCTL_NO_REFERENCE
227 status = semctl((*semid),*event,SETVAL,value);
229 status = semctl((*semid),*event,SETVAL,&value);
231 if (status < 0) return(0);
238 get_semaphore(int *semid, int *event, int *value)
239 /*=================================================
241 GET semaphore counter value
243 ==========================================================================*/
247 #ifdef SEMCTL_NO_REFERENCE
248 status = semctl((*semid),*event,GETVAL,value);
250 status = semctl((*semid),*event,GETVAL,&value);
253 if (status < 0) return(0);
261 remove_semaphore(int *semid, char *name)
262 /*======================================================
264 CLOSE semaphore attached to cluster
266 =============================================================================*/
270 /* status = semctl(*semid,IPC_RMID,NULL);*/
271 status = semctl(*semid,IPC_RMID,0);
272 if (status < 0) return 0;
279 osd_signl_(int *event)
280 /*====================================================
282 ARM the SIGNAL event (Must be 1 or 2 )
283 And WAIT after it was KILLED
285 =======================================================*/
287 signal(SIGUSER + *event , osd_signal_) ;
293 osd_skill_(int *pid, int *event)
294 /*==================================================
296 SEND a SIGNAL to the PROCESS ID specified
298 ====================================================*/
300 if( kill( *pid , SIGUSER + *event ) < 0 ) return (0) ;
305 osd_alarm_(int sec,RETSIGTYPE (*_alarm)())
306 /*====================================================
308 ARM the SIGNAL event (Must be 1 or 2 )
309 And WAIT after it was KILLED
311 ==========================================================================*/
313 signal(SIGALRM, _alarm) ;