16 #if !defined(HAS_GETTIMEOFDAY) && defined(WIN32)
17 #define HAS_GETTIMEOFDAY
19 /* shows up in winsock.h?
27 gettimeofday (struct timeval *tp, int nothing)
32 /* mktime converts local to UTC */
34 tmtm.tm_sec = st.wSecond;
35 tmtm.tm_min = st.wMinute;
36 tmtm.tm_hour = st.wHour;
37 tmtm.tm_mday = st.wDay;
38 tmtm.tm_mon = st.wMonth - 1;
39 tmtm.tm_year = st.wYear - 1900;
43 tp->tv_usec = st.wMilliseconds * 1000;
48 #if !defined(HAS_GETTIMEOFDAY) && defined(VMS)
49 #define HAS_GETTIMEOFDAY
51 #include <time.h> /* gettimeofday */
52 #include <stdlib.h> /* qdiv */
53 #include <starlet.h> /* sys$gettim */
57 VMS binary time is expressed in 100 nano-seconds since
58 system base time which is 17-NOV-1858 00:00:00.00
61 #define DIV_100NS_TO_SECS 10000000L
62 #define DIV_100NS_TO_USECS 10L
65 gettimeofday is supposed to return times since the epoch
66 so need to determine this in terms of VMS base time
68 static $DESCRIPTOR(dscepoch,"01-JAN-1970 00:00:00.00");
70 static __int64 base_adjust=0;
73 gettimeofday (struct timeval *tp, void *tpz)
80 In case of error, tv_usec = 0 and tv_sec = VMS condition code.
81 The return from function is also set to -1.
82 This is not exactly as per the manual page.
87 if (base_adjust==0) { /* Need to determine epoch adjustment */
88 ret=sys$bintim(&dscepoch,&base_adjust);
95 ret=sys$gettim(&quad); /* Get VMS system time */
96 if ((1 && ret) == 1) {
97 quad -= base_adjust; /* convert to epoch offset */
98 ans1=qdiv(quad,DIV_100NS_TO_SECS);
99 ans2=qdiv(ans1.rem,DIV_100NS_TO_USECS);
100 tp->tv_sec = ans1.quot; /* Whole seconds */
101 tp->tv_usec = ans2.quot; /* Micro-seconds */
110 #if !defined(HAS_USLEEP) && defined(HAS_SELECT)
111 #ifndef SELECT_IS_BROKEN
113 #define usleep hrt_usleep /* could conflict with ncurses for static build */
116 hrt_usleep(unsigned long usec)
121 select(0, (Select_fd_set_t)NULL, (Select_fd_set_t)NULL,
122 (Select_fd_set_t)NULL, &tv);
127 #if !defined(HAS_USLEEP) && defined(WIN32)
129 #define usleep hrt_usleep /* could conflict with ncurses for static build */
132 hrt_usleep(unsigned long usec)
141 #if !defined(HAS_UALARM) && defined(HAS_SETITIMER)
143 #define ualarm hrt_ualarm /* could conflict with ncurses for static build */
146 hrt_ualarm(int usec, int interval)
148 struct itimerval itv;
149 itv.it_value.tv_sec = usec / 1000000;
150 itv.it_value.tv_usec = usec % 1000000;
151 itv.it_interval.tv_sec = interval / 1000000;
152 itv.it_interval.tv_usec = interval % 1000000;
153 return setitimer(ITIMER_REAL, &itv, 0);
157 #ifdef HAS_GETTIMEOFDAY
164 status = gettimeofday (&Tp, NULL);
174 status = gettimeofday (&Tp, NULL);
175 return Tp.tv_sec + (Tp.tv_usec / 1000000.);
180 MODULE = Time::HiRes PACKAGE = Time::HiRes
185 #ifdef HAS_GETTIMEOFDAY
186 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime), 0);
187 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) myU2time), 0);
200 int useconds = fseconds * 1000000;
208 ualarm(useconds,interval=0)
213 alarm(fseconds,finterval=0)
217 int useconds, uinterval;
219 useconds = fseconds * 1000000;
220 uinterval = finterval * 1000000;
221 RETVAL = ualarm (useconds, uinterval);
225 #ifdef HAS_GETTIMEOFDAY
233 status = gettimeofday (&Tp, NULL);
234 if (GIMME == G_ARRAY) {
236 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
237 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
240 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
249 status = gettimeofday (&Tp, NULL);
250 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
256 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
259 # Revision 1.11 1999/03/16 02:27:38 wegscd
260 # Add U2time, NVtime. Fix symbols for static link.
262 # Revision 1.10 1998/09/30 02:36:25 wegscd
265 # Revision 1.9 1998/07/07 02:42:06 wegscd
268 # Revision 1.8 1998/07/02 01:47:26 wegscd
269 # Add Win32 code for gettimeofday.
271 # Revision 1.7 1997/11/13 02:08:12 wegscd
272 # Add missing EXTEND in gettimeofday() scalar code.
274 # Revision 1.6 1997/11/11 02:32:35 wegscd
275 # Do something useful when calling gettimeofday() in a scalar context.
276 # The patch is courtesy of Gisle Aas.
278 # Revision 1.5 1997/11/06 03:10:47 wegscd
279 # Fake ualarm() if we have setitimer.
281 # Revision 1.4 1997/11/05 05:41:23 wegscd
282 # Turn prototypes ON (suggested by Gisle Aas)
284 # Revision 1.3 1997/10/13 20:56:15 wegscd
285 # Add PROTOTYPES: DISABLE
287 # Revision 1.2 1997/05/23 01:01:38 wegscd
288 # Conditional compilation, depending on what the OS gives us.
290 # Revision 1.1 1996/09/03 18:26:35 wegscd