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 unsigned __int64 ft_i64;
71 /* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */
72 #define EPOCH_BIAS 116444736000000000i64
74 /* NOTE: This does not compute the timezone info (doing so can be expensive,
75 * and appears to be unsupported even by glibc) */
77 gettimeofday (struct timeval *tp, void *not_used)
81 /* this returns time in 100-nanosecond units (i.e. tens of usecs) */
82 GetSystemTimeAsFileTime(&ft.ft_val);
84 /* seconds since epoch */
85 tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / 10000000i64);
87 /* microseconds remaining */
88 tp->tv_usec = (long)((ft.ft_i64 / 10i64) % 1000000i64);
94 #if !defined(HAS_GETTIMEOFDAY) && defined(VMS)
95 #define HAS_GETTIMEOFDAY
97 #include <time.h> /* gettimeofday */
98 #include <stdlib.h> /* qdiv */
99 #include <starlet.h> /* sys$gettim */
102 #include <lib$routines.h> /* lib$ediv() */
106 VMS binary time is expressed in 100 nano-seconds since
107 system base time which is 17-NOV-1858 00:00:00.00
110 #define DIV_100NS_TO_SECS 10000000L
111 #define DIV_100NS_TO_USECS 10L
114 gettimeofday is supposed to return times since the epoch
115 so need to determine this in terms of VMS base time
117 static $DESCRIPTOR(dscepoch,"01-JAN-1970 00:00:00.00");
120 static long base_adjust[2]={0L,0L};
122 static __int64 base_adjust=0;
126 gettimeofday (struct timeval *tp, void *tpz)
132 long div_100ns_to_secs;
133 long div_100ns_to_usecs;
141 In case of error, tv_usec = 0 and tv_sec = VMS condition code.
142 The return from function is also set to -1.
143 This is not exactly as per the manual page.
149 if (base_adjust[0]==0 && base_adjust[1]==0) {
151 if (base_adjust==0) { /* Need to determine epoch adjustment */
153 ret=sys$bintim(&dscepoch,&base_adjust);
154 if (1 != (ret &&1)) {
160 ret=sys$gettim(&quad); /* Get VMS system time */
161 if ((1 && ret) == 1) {
163 quad[0] -= base_adjust[0]; /* convert to epoch offset */
164 quad[1] -= base_adjust[1]; /* convert 2nd half of quadword */
165 div_100ns_to_secs = DIV_100NS_TO_SECS;
166 div_100ns_to_usecs = DIV_100NS_TO_USECS;
167 lib$ediv(&div_100ns_to_secs,&quad,&quo,&rem);
170 lib$ediv(&div_100ns_to_usecs,&quad1,&quo1,&rem1);
171 tp->tv_sec = quo; /* Whole seconds */
172 tp->tv_usec = quo1; /* Micro-seconds */
174 quad -= base_adjust; /* convert to epoch offset */
175 ans1=qdiv(quad,DIV_100NS_TO_SECS);
176 ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS);
177 tp->tv_sec = ans1.quot; /* Whole seconds */
178 tp->tv_usec = ans2.quot; /* Micro-seconds */
188 #if !defined(HAS_USLEEP) && defined(HAS_SELECT)
189 #ifndef SELECT_IS_BROKEN
191 #define usleep hrt_usleep /* could conflict with ncurses for static build */
194 hrt_usleep(unsigned long usec)
199 select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL,
200 (Select_fd_set_t)NULL, &tv);
205 #if !defined(HAS_USLEEP) && defined(WIN32)
207 #define usleep hrt_usleep /* could conflict with ncurses for static build */
210 hrt_usleep(unsigned long usec)
219 #if !defined(HAS_UALARM) && defined(HAS_SETITIMER)
221 #define ualarm hrt_ualarm /* could conflict with ncurses for static build */
224 hrt_ualarm(int usec, int interval)
226 struct itimerval itv;
227 itv.it_value.tv_sec = usec / 1000000;
228 itv.it_value.tv_usec = usec % 1000000;
229 itv.it_interval.tv_sec = interval / 1000000;
230 itv.it_interval.tv_usec = interval % 1000000;
231 return setitimer(ITIMER_REAL, &itv, 0);
235 #ifdef HAS_GETTIMEOFDAY
242 status = gettimeofday (&Tp, NULL);
253 status = gettimeofday (&Tp, NULL);
254 return status == 0 ? Tp.tv_sec + (Tp.tv_usec / 1000000.) : -1.0;
259 MODULE = Time::HiRes PACKAGE = Time::HiRes
264 #ifdef HAS_GETTIMEOFDAY
267 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime()), 0);
268 if (myU2time(auv) == 0)
269 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) auv[0]), 0);
289 usleep((int)(SvNV(ST(0)) * 1000000));
298 ualarm(useconds,interval=0)
303 alarm(fseconds,finterval=0)
307 int useconds, uinterval;
309 useconds = fseconds * 1000000;
310 uinterval = finterval * 1000000;
311 RETVAL = ualarm (useconds, uinterval);
318 #ifdef HAS_GETTIMEOFDAY
326 status = gettimeofday (&Tp, NULL);
327 if (GIMME == G_ARRAY) {
329 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
330 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
333 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
342 status = gettimeofday (&Tp, NULL);
343 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
349 #if defined(HAS_GETITIMER) && defined(HAS_SETITIMER)
351 #define TV2NV(tv) ((NV)((tv).tv_sec) + 0.000001 * (NV)((tv).tv_usec))
354 setitimer(which, seconds, interval = 0)
359 struct itimerval newit;
360 struct itimerval oldit;
362 newit.it_value.tv_sec = seconds;
363 newit.it_value.tv_usec =
364 (seconds - (NV)newit.it_value.tv_sec) * 1000000.0;
365 newit.it_interval.tv_sec = interval;
366 newit.it_interval.tv_usec =
367 (interval - (NV)newit.it_interval.tv_sec) * 1000000.0;
368 if (setitimer(which, &newit, &oldit) == 0) {
370 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_value))));
371 if (GIMME == G_ARRAY) {
373 PUSHs(sv_2mortal(newSVnv(TV2NV(oldit.it_interval))));
381 struct itimerval nowit;
383 if (getitimer(which, &nowit) == 0) {
385 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_value))));
386 if (GIMME == G_ARRAY) {
388 PUSHs(sv_2mortal(newSVnv(TV2NV(nowit.it_interval))));
394 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
397 # Revision 1.11 1999/03/16 02:27:38 wegscd
398 # Add U2time, NVtime. Fix symbols for static link.
400 # Revision 1.10 1998/09/30 02:36:25 wegscd
403 # Revision 1.9 1998/07/07 02:42:06 wegscd
406 # Revision 1.8 1998/07/02 01:47:26 wegscd
407 # Add Win32 code for gettimeofday.
409 # Revision 1.7 1997/11/13 02:08:12 wegscd
410 # Add missing EXTEND in gettimeofday() scalar code.
412 # Revision 1.6 1997/11/11 02:32:35 wegscd
413 # Do something useful when calling gettimeofday() in a scalar context.
414 # The patch is courtesy of Gisle Aas.
416 # Revision 1.5 1997/11/06 03:10:47 wegscd
417 # Fake ualarm() if we have setitimer.
419 # Revision 1.4 1997/11/05 05:41:23 wegscd
420 # Turn prototypes ON (suggested by Gisle Aas)
422 # Revision 1.3 1997/10/13 20:56:15 wegscd
423 # Add PROTOTYPES: DISABLE
425 # Revision 1.2 1997/05/23 01:01:38 wegscd
426 # Conditional compilation, depending on what the OS gives us.
428 # Revision 1.1 1996/09/03 18:26:35 wegscd