| 1 |
/* @(#)ose.c 19.1 (ES0-DMD) 02/25/03 13:56:11 */ |
| 2 |
/*=========================================================================== |
| 3 |
Copyright (C) 1995 European Southern Observatory (ESO) |
| 4 |
|
| 5 |
This program is free software; you can redistribute it and/or |
| 6 |
modify it under the terms of the GNU General Public License as |
| 7 |
published by the Free Software Foundation; either version 2 of |
| 8 |
the License, or (at your option) any later version. |
| 9 |
|
| 10 |
This program is distributed in the hope that it will be useful, |
| 11 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 |
GNU General Public License for more details. |
| 14 |
|
| 15 |
You should have received a copy of the GNU General Public |
| 16 |
License along with this program; if not, write to the Free |
| 17 |
Software Foundation, Inc., 675 Massachusetss Ave, Cambridge, |
| 18 |
MA 02139, USA. |
| 19 |
|
| 20 |
Corresponding concerning ESO-MIDAS should be addressed as follows: |
| 21 |
Internet e-mail: [email protected] |
| 22 |
Postal address: European Southern Observatory |
| 23 |
Data Management Division |
| 24 |
Karl-Schwarzschild-Strasse 2 |
| 25 |
D 85748 Garching bei Muenchen |
| 26 |
GERMANY |
| 27 |
===========================================================================*/ |
| 28 |
|
| 29 |
/*++++++++++++ |
| 30 |
.TYPE Module |
| 31 |
.NAME ose |
| 32 |
.LANGUAGE C |
| 33 |
.AUTHOR IPG-ESO Garching (B. Pirenne) |
| 34 |
.CATEGORY Host operating system interfaces. Interprocess event flags |
| 35 |
.COMMENTS |
| 36 |
These routines will handle the interprocess events flags. |
| 37 |
They will allow the following : |
| 38 |
* prepare a process to receive information in event flags |
| 39 |
* set an event flag among the process group |
| 40 |
* clear an event flag among the process group |
| 41 |
* read the state of an event flag |
| 42 |
* wait for an event flag to be set. |
| 43 |
.VERSION 0.0 29-Jan-1987 Definition B. Pirenne, D. Ponz, P. |
| 44 |
Linde |
| 45 |
.VERSION 1.0 30-Jan-1987 Programmation B. Pirenne |
| 46 |
.REMARKS VMS / UNIX SYSV + BSD Version |
| 47 |
----------*/ |
| 48 |
|
| 49 |
#include <errno.h> |
| 50 |
#include <osparms.h> |
| 51 |
#include <osdefos.h> |
| 52 |
/* MID_EXTERN int oserror; (defined in osparms.h. tm04.09.89) */ |
| 53 |
|
| 54 |
#if MID_OS_VMS |
| 55 |
# include <ssdef.h> |
| 56 |
extern int vmserror; |
| 57 |
#else |
| 58 |
static unsigned char *flag = NULL_PTR(unsigned char); |
| 59 |
#endif |
| 60 |
|
| 61 |
#if (!MID_OS_VMS) |
| 62 |
/*===================================================================*/ |
| 63 |
int oseprep() |
| 64 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 65 |
.PURPOSE prepare the event flags in a newly created process. |
| 66 |
.METHOD Simply gets the shared memory address and put it into the |
| 67 |
character pointer "flag" defined in <osparms.h>. |
| 68 |
.RETURNS Upon successful completion a value of zero is returned, else -1 |
| 69 |
is returned and ``oserror'' is set to the actual error code. |
| 70 |
.REMARKS System dependencies: |
| 71 |
-- UNIX: osmshget(0) |
| 72 |
.REMARKS This service is best run as the first statement of a process. |
| 73 |
-----------*/ |
| 74 |
{ |
| 75 |
flag = (unsigned char *)osmalloc(_NFLAGS); |
| 76 |
if (flag) oscfill(flag, _NFLAGS, 0); |
| 77 |
return(oserror ? -1 : 0); |
| 78 |
} |
| 79 |
#endif |
| 80 |
|
| 81 |
/*===================================================================*/ |
| 82 |
int oseset(eid) |
| 83 |
/*+++++++ |
| 84 |
.PURPOSE sets a flag (flag is set among all the processes) |
| 85 |
.RETURNS Value 0 on normal return. |
| 86 |
.METHOD 1. Check if the flag number is good |
| 87 |
.METHOD 2. Set the flag. |
| 88 |
.REMARKS |
| 89 |
------------------------------------------------------------*/ |
| 90 |
int eid; /* IN : identification of the flag to set */ |
| 91 |
{ |
| 92 |
register int i; |
| 93 |
|
| 94 |
if (eid <= 0 || eid > _NFLAGS) |
| 95 |
oserror = EINVAL; |
| 96 |
else |
| 97 |
{ |
| 98 |
#if MID_OS_VMS |
| 99 |
vmserror = SYS$SETEF(eid); |
| 100 |
oserror = (vmserror&1 ? 0 : EINTR); |
| 101 |
#else |
| 102 |
i = eid-1, oserror = 0; |
| 103 |
if (!flag) oseprep(); |
| 104 |
*(flag + i) = 1; |
| 105 |
#endif |
| 106 |
} |
| 107 |
|
| 108 |
return(oserror ? -1 : 0); |
| 109 |
} |
| 110 |
|
| 111 |
/*===================================================================*/ |
| 112 |
int oseclear(eid) |
| 113 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 114 |
.PURPOSE clears a flag (flag is cleared among all the processes) |
| 115 |
.RETURNS Value 0 on normal return. |
| 116 |
.METHOD 1. Check if the flag number is good |
| 117 |
.METHOD 2. Clear the given flag. |
| 118 |
.REMARKS |
| 119 |
------------------------------------------------------------*/ |
| 120 |
int eid; /* IN : identification of the flag to clear */ |
| 121 |
{ |
| 122 |
register int i; |
| 123 |
|
| 124 |
if (eid <= 0 || eid > _NFLAGS) |
| 125 |
oserror = EINVAL; |
| 126 |
else |
| 127 |
{ |
| 128 |
#if MID_OS_VMS |
| 129 |
vmserror = SYS$CLREF(eid); |
| 130 |
oserror = (vmserror&1 ? 0 : EINTR); |
| 131 |
#else |
| 132 |
i = eid-1, oserror = 0; |
| 133 |
if (!flag) oseprep(); |
| 134 |
*(flag + i) = 0; |
| 135 |
#endif |
| 136 |
} |
| 137 |
|
| 138 |
return(oserror ? -1 : 0); |
| 139 |
} |
| 140 |
|
| 141 |
/*===================================================================*/ |
| 142 |
int oseread(eid) |
| 143 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 144 |
.PURPOSE check the state of a flag. |
| 145 |
.RETURNS The value of the flag (0 or 1) or -1 in the signal number was |
| 146 |
not valid. |
| 147 |
.REMARKS |
| 148 |
------------------------------------------------------------*/ |
| 149 |
int eid; /* IN : identification of the flag to check */ |
| 150 |
{ |
| 151 |
int ret; |
| 152 |
|
| 153 |
if (eid <= 0 || eid > _NFLAGS) |
| 154 |
oserror = EINVAL; |
| 155 |
else |
| 156 |
{ |
| 157 |
#if MID_OS_VMS |
| 158 |
vmserror = SYS$READEF(eid, &ret); |
| 159 |
oserror = (vmserror&1 ? 0 : EINTR); |
| 160 |
#else |
| 161 |
ret = eid-1, oserror = 0; |
| 162 |
if (!flag) oseprep(); |
| 163 |
ret = *(flag + ret); |
| 164 |
#endif |
| 165 |
} |
| 166 |
return(oserror ? -1 : ret); |
| 167 |
} |
| 168 |
|
| 169 |
/*===================================================================*/ |
| 170 |
int osewait(eid) |
| 171 |
/*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
| 172 |
.PURPOSE Waits for a flag to be received |
| 173 |
.RETURNS returns always 0. |
| 174 |
.METHOD loop until the flag eid is set. The loop pauses for one second between |
| 175 |
each new check. |
| 176 |
.REMARKS |
| 177 |
------------------------------------------------------------*/ |
| 178 |
int eid; /* IN : event flag identification */ |
| 179 |
{ |
| 180 |
#if MID_OS_VMS |
| 181 |
if (eid <= 0 || eid > _NFLAGS) |
| 182 |
oserror = EINVAL; |
| 183 |
else vmserror = SYS$WAITFR(eid), oserror = (vmserror&1 ? 0 : EINTR); |
| 184 |
#else |
| 185 |
while (oseread(eid) == 0) |
| 186 |
ospwait(1); |
| 187 |
#endif |
| 188 |
|
| 189 |
return(oserror ? -1 : 0); |
| 190 |
} |