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);
215 status = gettimeofday (&Tp, NULL);
216 return status == 0 ? Tp.tv_sec + (Tp.tv_usec / 1000000.) : -1.0;
221 MODULE = Time::HiRes PACKAGE = Time::HiRes
226 #ifdef HAS_GETTIMEOFDAY
229 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime()), 0);
230 if (myU2time(auv) == 0)
231 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) auv[0]), 0);
250 int useconds = fseconds * 1000000;
258 ualarm(useconds,interval=0)
263 alarm(fseconds,finterval=0)
267 int useconds, uinterval;
269 useconds = fseconds * 1000000;
270 uinterval = finterval * 1000000;
271 RETVAL = ualarm (useconds, uinterval);
278 #ifdef HAS_GETTIMEOFDAY
286 status = gettimeofday (&Tp, NULL);
287 if (GIMME == G_ARRAY) {
289 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
290 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
293 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
302 status = gettimeofday (&Tp, NULL);
303 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
309 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)
311 #define TV2NV(tv) ((NV)((tv).tv_sec) + 0.000001 * (NV)((tv).tv_usec))
314 setitimer(which, seconds, interval = 0)
319 struct itimerval newit;
320 struct itimerval oldit;
322 newit.it_value.tv_sec = seconds;
323 newit.it_value.tv_usec =
324 (seconds - (NV)newit.it_value.tv_sec) * 1000000.0;
325 newit.it_interval.tv_sec = interval;
326 newit.it_interval.tv_usec =
327 (interval - (NV)newit.it_interval.tv_sec) * 1000000.0;
328 if (setitimer(which, &newit, &oldit) == 0) {
330 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_value))));
331 if (GIMME == G_ARRAY) {
333 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_interval))));
341 struct itimerval nowit;
343 if (getitimer(which, &nowit) == 0) {
345 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_value))));
346 if (GIMME == G_ARRAY) {
348 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_interval))));
354 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
357 # Revision 1.11 1999/03/16 02:27:38 wegscd
358 # Add U2time, NVtime. Fix symbols for static link.
360 # Revision 1.10 1998/09/30 02:36:25 wegscd
363 # Revision 1.9 1998/07/07 02:42:06 wegscd
366 # Revision 1.8 1998/07/02 01:47:26 wegscd
367 # Add Win32 code for gettimeofday.
369 # Revision 1.7 1997/11/13 02:08:12 wegscd
370 # Add missing EXTEND in gettimeofday() scalar code.
372 # Revision 1.6 1997/11/11 02:32:35 wegscd
373 # Do something useful when calling gettimeofday() in a scalar context.
374 # The patch is courtesy of Gisle Aas.
376 # Revision 1.5 1997/11/06 03:10:47 wegscd
377 # Fake ualarm() if we have setitimer.
379 # Revision 1.4 1997/11/05 05:41:23 wegscd
380 # Turn prototypes ON (suggested by Gisle Aas)
382 # Revision 1.3 1997/10/13 20:56:15 wegscd
383 # Add PROTOTYPES: DISABLE
385 # Revision 1.2 1997/05/23 01:01:38 wegscd
386 # Conditional compilation, depending on what the OS gives us.
388 # Revision 1.1 1996/09/03 18:26:35 wegscd