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 ATLEASTFIVEOHOHFIVE
186 #ifdef HAS_GETTIMEOFDAY
187 hv_store(PL_modglobal, "Time::NVtime", 12, newSViv((IV) myNVtime), 0);
188 hv_store(PL_modglobal, "Time::U2time", 12, newSViv((IV) myU2time), 0);
202 int useconds = fseconds * 1000000;
210 ualarm(useconds,interval=0)
215 alarm(fseconds,finterval=0)
219 int useconds, uinterval;
221 useconds = fseconds * 1000000;
222 uinterval = finterval * 1000000;
223 RETVAL = ualarm (useconds, uinterval);
227 #ifdef HAS_GETTIMEOFDAY
235 status = gettimeofday (&Tp, NULL);
236 if (GIMME == G_ARRAY) {
238 PUSHs(sv_2mortal(newSViv(Tp.tv_sec)));
239 PUSHs(sv_2mortal(newSViv(Tp.tv_usec)));
242 PUSHs(sv_2mortal(newSVnv(Tp.tv_sec + (Tp.tv_usec / 1000000.0))));
251 status = gettimeofday (&Tp, NULL);
252 RETVAL = Tp.tv_sec + (Tp.tv_usec / 1000000.);
258 # $Id: HiRes.xs,v 1.11 1999/03/16 02:27:38 wegscd Exp wegscd $
261 # Revision 1.11 1999/03/16 02:27:38 wegscd
262 # Add U2time, NVtime. Fix symbols for static link.
264 # Revision 1.10 1998/09/30 02:36:25 wegscd
267 # Revision 1.9 1998/07/07 02:42:06 wegscd
270 # Revision 1.8 1998/07/02 01:47:26 wegscd
271 # Add Win32 code for gettimeofday.
273 # Revision 1.7 1997/11/13 02:08:12 wegscd
274 # Add missing EXTEND in gettimeofday() scalar code.
276 # Revision 1.6 1997/11/11 02:32:35 wegscd
277 # Do something useful when calling gettimeofday() in a scalar context.
278 # The patch is courtesy of Gisle Aas.
280 # Revision 1.5 1997/11/06 03:10:47 wegscd
281 # Fake ualarm() if we have setitimer.
283 # Revision 1.4 1997/11/05 05:41:23 wegscd
284 # Turn prototypes ON (suggested by Gisle Aas)
286 # Revision 1.3 1997/10/13 20:56:15 wegscd
287 # Add PROTOTYPES: DISABLE
289 # Revision 1.2 1997/05/23 01:01:38 wegscd
290 # Conditional compilation, depending on what the OS gives us.
292 # Revision 1.1 1996/09/03 18:26:35 wegscd