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 */
96 #include <lib$routines.h> /* lib$ediv() */
100 VMS binary time is expressed in 100 nano-seconds since
101 system base time which is 17-NOV-1858 00:00:00.00
104 #define DIV_100NS_TO_SECS 10000000L
105 #define DIV_100NS_TO_USECS 10L
108 gettimeofday is supposed to return times since the epoch
109 so need to determine this in terms of VMS base time
111 static $DESCRIPTOR(dscepoch,"01-JAN-1970 00:00:00.00");
114 static long base_adjust[2]={0L,0L};
116 static __int64 base_adjust=0;
120 gettimeofday (struct timeval *tp, void *tpz)
126 long div_100ns_to_secs;
127 long div_100ns_to_usecs;
135 In case of error, tv_usec = 0 and tv_sec = VMS condition code.
136 The return from function is also set to -1.
137 This is not exactly as per the manual page.
143 if (base_adjust[0]==0 && base_adjust[1]==0) {
145 if (base_adjust==0) { /* Need to determine epoch adjustment */
147 ret=sys$bintim(&dscepoch,&base_adjust);
148 if (1 != (ret &&1)) {
154 ret=sys$gettim(&quad); /* Get VMS system time */
155 if ((1 && ret) == 1) {
157 quad[0] -= base_adjust[0]; /* convert to epoch offset */
158 quad[1] -= base_adjust[1]; /* convert 2nd half of quadword */
159 div_100ns_to_secs = DIV_100NS_TO_SECS;
160 div_100ns_to_usecs = DIV_100NS_TO_USECS;
161 lib$ediv(&div_100ns_to_secs,&quad,&quo,&rem);
164 lib$ediv(&div_100ns_to_usecs,&quad1,&quo1,&rem1);
165 tp->tv_sec = quo; /* Whole seconds */
166 tp->tv_usec = quo1; /* Micro-seconds */
168 quad -= base_adjust; /* convert to epoch offset */
169 ans1=qdiv(quad,DIV_100NS_TO_SECS);
170 ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS);
171 tp->tv_sec = ans1.quot; /* Whole seconds */
172 tp->tv_usec = ans2.quot; /* Micro-seconds */
182 #if !defined(HAS_USLEEP) && defined(HAS_SELECT)
183 #ifndef SELECT_IS_BROKEN
185 #define usleep hrt_usleep /* could conflict with ncurses for static build */
188 hrt_usleep(unsigned long usec)
193 select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL,
194 (Select_fd_set_t)NULL, &tv);
199 #if !defined(HAS_USLEEP) && defined(WIN32)
201 #define usleep hrt_usleep /* could conflict with ncurses for static build */
204 hrt_usleep(unsigned long usec)
213 #if !defined(HAS_UALARM) && defined(HAS_SETITIMER)
215 #define ualarm hrt_ualarm /* could conflict with ncurses for static build */
218 hrt_ualarm(int usec, int interval)
220 struct itimerval itv;
221 itv.it_value.tv_sec = usec / 1000000;
222 itv.it_value.tv_usec = usec % 1000000;
223 itv.it_interval.tv_sec = interval / 1000000;
224 itv.it_interval.tv_usec = interval % 1000000;
225 return setitimer(ITIMER_REAL, &itv, 0);
229 #ifdef HAS_GETTIMEOFDAY
236 status = gettimeofday (&Tp, NULL);
247 status = gettimeofday (&Tp, NULL);
248 return status == 0 ? Tp.tv_sec + (Tp.tv_usec / 1000000.) : -1.0;
253 MODULE = Time::HiRes PACKAGE = Time::HiRes
258 #ifdef HAS_GETTIMEOFDAY
261 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime()), 0);
262 if (myU2time(auv) == 0)
263 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) auv[0]), 0);
282 usleep((int)(SvNV(ST(0)) * 1000000));
291 ualarm(useconds,interval=0)
296 alarm(fseconds,finterval=0)
300 int useconds, uinterval;
302 useconds = fseconds * 1000000;
303 uinterval = finterval * 1000000;
304 RETVAL = ualarm (useconds, uinterval);
311 #ifdef HAS_GETTIMEOFDAY
319 status = gettimeofday (&Tp, NULL);
320 if (GIMME == G_ARRAY) {
322 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
323 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
326 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
335 status = gettimeofday (&Tp, NULL);
336 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
342 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)
344 #define TV2NV(tv) ((NV)((tv).tv_sec) + 0.000001 * (NV)((tv).tv_usec))
347 setitimer(which, seconds, interval = 0)
352 struct itimerval newit;
353 struct itimerval oldit;
355 newit.it_value.tv_sec = seconds;
356 newit.it_value.tv_usec =
357 (seconds - (NV)newit.it_value.tv_sec) * 1000000.0;
358 newit.it_interval.tv_sec = interval;
359 newit.it_interval.tv_usec =
360 (interval - (NV)newit.it_interval.tv_sec) * 1000000.0;
361 if (setitimer(which, &newit, &oldit) == 0) {
363 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_value))));
364 if (GIMME == G_ARRAY) {
366 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_interval))));
374 struct itimerval nowit;
376 if (getitimer(which, &nowit) == 0) {
378 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_value))));
379 if (GIMME == G_ARRAY) {
381 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_interval))));
387 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
390 # Revision 1.11 1999/03/16 02:27:38 wegscd
391 # Add U2time, NVtime. Fix symbols for static link.
393 # Revision 1.10 1998/09/30 02:36:25 wegscd
396 # Revision 1.9 1998/07/07 02:42:06 wegscd
399 # Revision 1.8 1998/07/02 01:47:26 wegscd
400 # Add Win32 code for gettimeofday.
402 # Revision 1.7 1997/11/13 02:08:12 wegscd
403 # Add missing EXTEND in gettimeofday() scalar code.
405 # Revision 1.6 1997/11/11 02:32:35 wegscd
406 # Do something useful when calling gettimeofday() in a scalar context.
407 # The patch is courtesy of Gisle Aas.
409 # Revision 1.5 1997/11/06 03:10:47 wegscd
410 # Fake ualarm() if we have setitimer.
412 # Revision 1.4 1997/11/05 05:41:23 wegscd
413 # Turn prototypes ON (suggested by Gisle Aas)
415 # Revision 1.3 1997/10/13 20:56:15 wegscd
416 # Add PROTOTYPES: DISABLE
418 # Revision 1.2 1997/05/23 01:01:38 wegscd
419 # Conditional compilation, depending on what the OS gives us.
421 # Revision 1.1 1996/09/03 18:26:35 wegscd