Debian Codegraph @

libsrc/os/vms/ospwait.c

raw
1 /* @(#)ospwait.c 19.1 (ES0-DMD) 02/25/03 13:56:13 */
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 ospwait
32 .LANGUAGE C
33 .AUTHOR IPG-ESO Garching
34 .CATEGORY Host operating system interfaces, Simplest Process controls.
35 .ENVIRONMENT VAX/VMS Version
36 .COMMENTS These routines give the capabilitites to the current process
37 to wait unconditionnaly.
38 .VERSION 1.0 20-Jan-1988 Creation, F. Ochsenbein
39 .VERSION 1.1 02-May-1990 Added ospexit
40 ------------------------------------------------------------*/
41
42 #include <osdefos.h>
43
44 # include <errno.h> /* System */
45 # include <ssdef.h> /* System */
46 # define ENTER() oserror = 0; vmserror = 0;
47 # define EXIT(x) FIN: if ((!(vmserror & 1))&&(oserror==0)) \
48 oserror = EINTR; \
49 return(oserror ? -1 : x);
50 MID_EXTERN int vmserror;
51 MID_EXTERN int oserror;
52
53 #define FINISH goto FIN
54
55 /*=========================================================================
56 ospwait
57 *=========================================================================*/
58 int ospwait(s)
59 /*+++
60 .PURPOSE Wait for a specified number of seconds
61 .RETURNS 0 (success) / -1 (failure)
62 .REMARKS
63 ---*/
64 int s; /* Time to wait in s */
65 {
66 return(ospwms(s*1000));
67 }
68
69 /*=========================================================================
70 ospuwait
71 *=========================================================================*/
72 int ospuwait(ms)
73 unsigned int ms; /* IN : time delay in milliseconds */
74
75 {
76 return(ospwms(ms));
77 }
78
79
80 /*
81
82 */
83
84 /*=========================================================================
85 ospwms
86 *=========================================================================*/
87 int ospwms(ms)
88 /*+++
89 .PURPOSE Wait for a specified number of milliseconds
90 .RETURNS 0 / -1
91 .REMARKS
92 ---*/
93 unsigned int ms; /* Time to wait in ms */
94 {
95 MID_STATIC unsigned long int efn = 0; /* Event flag */
96 MID_STATIC long int btime[2] = {-1,-1};
97 register unsigned int mod;
98
99 ENTER();
100
101 /* If no efn, get one */
102 if (efn == 0)
103 { LIB$GET_EF(&efn); /* Get an event flag ... */
104 SYS$CLREF(efn); /* ... and clear it */
105 }
106
107 vmserror = SS$_NORMAL;
108
109 for (mod = ms; mod != 0; mod /= 180000) /* Use a loop, (3 mn) */
110 { btime[0] = -10000 * (mod%180000 ? mod%180000 : 180000);
111 if (!((vmserror = SYS$SETIMR(efn, btime, 0,0)) &1)) FINISH;
112 if (!((vmserror = SYS$WAITFR(efn)) &1)) FINISH;
113 }
114
115 EXIT(0);
116 }
117
118 /*=========================================================================*/
119 int ospexit(status)
120 /*+++
121 .PURPOSE Terminate propoerly the Main program
122 .RETURNS Nothing
123 .REMARKS
124 ---*/
125 int status; /* IN: Status 0 for OK / 1 for ABORT / Other */
126 {
127 switch (status) {
128 case 0: SYS$EXIT(1);
129 case 1: SYS$EXIT(SS$_ABORT /* 44 */);
130 default: SYS$EXIT(status);
131 }
132 return(0);
133 }