summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGurusamy Sarathy <gsar@cpan.org>2001-09-25 15:19:13 +0000
committerGurusamy Sarathy <gsar@cpan.org>2001-09-25 15:19:13 +0000
commiteb1a5092cedc56e09684f2bb18507cb7a80dafdb (patch)
tree6d52ee2f460be29614e01967fc77e3fcef73eb13
parent69026470e9d2e2c7bf7b03f351d6e98a6d6f29f3 (diff)
downloadperl-eb1a5092cedc56e09684f2bb18507cb7a80dafdb.tar.gz
avoid the use of ftime() (it does a useless, potentially
expensive call to GetTimeZoneInformation()); this potentially also results in three more digits of precision from Time::HiRes::time() p4raw-id: //depot/perl@12199
-rw-r--r--ext/Time/HiRes/HiRes.xs30
1 files changed, 23 insertions, 7 deletions
diff --git a/ext/Time/HiRes/HiRes.xs b/ext/Time/HiRes/HiRes.xs
index a0349fa698..8e5be079a4 100644
--- a/ext/Time/HiRes/HiRes.xs
+++ b/ext/Time/HiRes/HiRes.xs
@@ -62,16 +62,32 @@ struct timeval {
long tv_usec;
}
*/
-#include <sys/timeb.h>
+typedef union {
+ unsigned __int64 ft_i64;
+ FILETIME ft_val;
+} FT_t;
+
+/* Number of 100 nanosecond units from 1/1/1601 to 1/1/1970 */
+#define EPOCH_BIAS 116444736000000000i64
+
+/* NOTE: This does not compute the timezone info (doing so can be expensive,
+ * and appears to be unsupported even by glibc) */
int
-gettimeofday (struct timeval *tp, int nothing)
+gettimeofday (struct timeval *tp, void *not_used)
{
- struct _timeb timebuffer;
- _ftime( &timebuffer );
- tp->tv_sec = timebuffer.time;
- tp->tv_usec = timebuffer.millitm * 1000;
- return 0;
+ FT_t ft;
+
+ /* this returns time in 100-nanosecond units (i.e. tens of usecs) */
+ GetSystemTimeAsFileTime(&ft.ft_val);
+
+ /* seconds since epoch */
+ tp->tv_sec = (long)((ft.ft_i64 - EPOCH_BIAS) / 10000000i64);
+
+ /* microseconds remaining */
+ tp->tv_usec = (long)((ft.ft_i64 / 10i64) % 1000000i64);
+
+ return 0;
}
#endif