17 constant(char *name, int arg)
22 if (strEQ(name, "ITIMER_REAL"))
28 if (strEQ(name, "ITIMER_REALPROF"))
29 #ifdef ITIMER_REALPROF
30 return ITIMER_REALPROF;
34 if (strEQ(name, "ITIMER_VIRTUAL"))
36 return ITIMER_VIRTUAL;
40 if (strEQ(name, "ITIMER_PROF"))
56 #if !defined(HAS_GETTIMEOFDAY) && defined(WIN32)
57 #define HAS_GETTIMEOFDAY
59 /* shows up in winsock.h?
67 gettimeofday (struct timeval *tp, int nothing)
72 /* mktime converts local to UTC */
74 tmtm.tm_sec = st.wSecond;
75 tmtm.tm_min = st.wMinute;
76 tmtm.tm_hour = st.wHour;
77 tmtm.tm_mday = st.wDay;
78 tmtm.tm_mon = st.wMonth - 1;
79 tmtm.tm_year = st.wYear - 1900;
83 tp->tv_usec = st.wMilliseconds * 1000;
88 #if !defined(HAS_GETTIMEOFDAY) && defined(VMS)
89 #define HAS_GETTIMEOFDAY
91 #include <time.h> /* gettimeofday */
92 #include <stdlib.h> /* qdiv */
93 #include <starlet.h> /* sys$gettim */
97 VMS binary time is expressed in 100 nano-seconds since
98 system base time which is 17-NOV-1858 00:00:00.00
101 #define DIV_100NS_TO_SECS 10000000L
102 #define DIV_100NS_TO_USECS 10L
105 gettimeofday is supposed to return times since the epoch
106 so need to determine this in terms of VMS base time
108 static $DESCRIPTOR(dscepoch,"01-JAN-1970 00:00:00.00");
110 static __int64 base_adjust=0;
113 gettimeofday (struct timeval *tp, void *tpz)
120 In case of error, tv_usec = 0 and tv_sec = VMS condition code.
121 The return from function is also set to -1.
122 This is not exactly as per the manual page.
127 if (base_adjust==0) { /* Need to determine epoch adjustment */
128 ret=sys$bintim(&dscepoch,&base_adjust);
129 if (1 != (ret &&1)) {
135 ret=sys$gettim(&quad); /* Get VMS system time */
136 if ((1 && ret) == 1) {
137 quad -= base_adjust; /* convert to epoch offset */
138 ans1=qdiv(quad,DIV_100NS_TO_SECS);
139 ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS);
140 tp->tv_sec = ans1.quot; /* Whole seconds */
141 tp->tv_usec = ans2.quot; /* Micro-seconds */
150 #if !defined(HAS_USLEEP) && defined(HAS_SELECT)
151 #ifndef SELECT_IS_BROKEN
153 #define usleep hrt_usleep /* could conflict with ncurses for static build */
156 hrt_usleep(unsigned long usec)
161 select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL,
162 (Select_fd_set_t)NULL, &tv);
167 #if !defined(HAS_USLEEP) && defined(WIN32)
169 #define usleep hrt_usleep /* could conflict with ncurses for static build */
172 hrt_usleep(unsigned long usec)
181 #if !defined(HAS_UALARM) && defined(HAS_SETITIMER)
183 #define ualarm hrt_ualarm /* could conflict with ncurses for static build */
186 hrt_ualarm(int usec, int interval)
188 struct itimerval itv;
189 itv.it_value.tv_sec = usec / 1000000;
190 itv.it_value.tv_usec = usec % 1000000;
191 itv.it_interval.tv_sec = interval / 1000000;
192 itv.it_interval.tv_usec = interval % 1000000;
193 return setitimer(ITIMER_REAL, &itv, 0);
197 #ifdef HAS_GETTIMEOFDAY
204 status = gettimeofday (&Tp, NULL);
214 status = gettimeofday (&Tp, NULL);
215 return Tp.tv_sec + (Tp.tv_usec / 1000000.);
220 MODULE = Time::HiRes PACKAGE = Time::HiRes
225 #ifdef HAS_GETTIMEOFDAY
226 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime), 0);
227 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) myU2time), 0);
245 int useconds = fseconds * 1000000;
253 ualarm(useconds,interval=0)
258 alarm(fseconds,finterval=0)
262 int useconds, uinterval;
264 useconds = fseconds * 1000000;
265 uinterval = finterval * 1000000;
266 RETVAL = ualarm (useconds, uinterval);
270 #ifdef HAS_GETTIMEOFDAY
278 status = gettimeofday (&Tp, NULL);
279 if (GIMME == G_ARRAY) {
281 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
282 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
285 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
294 status = gettimeofday (&Tp, NULL);
295 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
301 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)
303 #define TV2NV(tv) ((NV)((tv).tv_sec) + 0.000001 * (NV)((tv).tv_usec))
306 setitimer(which, seconds, interval = 0)
311 struct itimerval newit;
312 struct itimerval oldit;
314 newit.it_value.tv_sec = seconds;
315 newit.it_value.tv_usec =
316 (seconds - (NV)newit.it_value.tv_sec) * 1000000.0;
317 newit.it_interval.tv_sec = interval;
318 newit.it_interval.tv_usec =
319 (interval - (NV)newit.it_interval.tv_sec) * 1000000.0;
320 if (setitimer(which, &newit, &oldit) == 0) {
322 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_value))));
323 if (GIMME == G_ARRAY) {
325 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_interval))));
333 struct itimerval nowit;
335 if (getitimer(which, &nowit) == 0) {
337 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_value))));
338 if (GIMME == G_ARRAY) {
340 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_interval))));
346 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
349 # Revision 1.11 1999/03/16 02:27:38 wegscd
350 # Add U2time, NVtime. Fix symbols for static link.
352 # Revision 1.10 1998/09/30 02:36:25 wegscd
355 # Revision 1.9 1998/07/07 02:42:06 wegscd
358 # Revision 1.8 1998/07/02 01:47:26 wegscd
359 # Add Win32 code for gettimeofday.
361 # Revision 1.7 1997/11/13 02:08:12 wegscd
362 # Add missing EXTEND in gettimeofday() scalar code.
364 # Revision 1.6 1997/11/11 02:32:35 wegscd
365 # Do something useful when calling gettimeofday() in a scalar context.
366 # The patch is courtesy of Gisle Aas.
368 # Revision 1.5 1997/11/06 03:10:47 wegscd
369 # Fake ualarm() if we have setitimer.
371 # Revision 1.4 1997/11/05 05:41:23 wegscd
372 # Turn prototypes ON (suggested by Gisle Aas)
374 # Revision 1.3 1997/10/13 20:56:15 wegscd
375 # Add PROTOTYPES: DISABLE
377 # Revision 1.2 1997/05/23 01:01:38 wegscd
378 # Conditional compilation, depending on what the OS gives us.
380 # Revision 1.1 1996/09/03 18:26:35 wegscd