summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-07-11 16:10:34 -0700
committerKeith Packard <keithp@keithp.com>2013-10-31 16:58:21 -0700
commit2d96948ab5c952b68875ac63844cf7d778d4bf63 (patch)
tree77db617195cdba9a1ee8e7bd29412e9af0978154 /os
parent0c33f47281c36726848daf513fb0483cdea57bff (diff)
os: Add GetTimeInMicros
64-bit higher resolution current time value. Signed-off-by: Keith Packard <keithp@keithp.com> Reviewed-by: Adam Jackson <ajax@redhat.com>
Diffstat (limited to 'os')
-rw-r--r--os/utils.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/os/utils.c b/os/utils.c
index 97c3125e6..995f62a37 100644
--- a/os/utils.c
+++ b/os/utils.c
@@ -430,6 +430,11 @@ GetTimeInMillis(void)
{
return GetTickCount();
}
+CARD64
+GetTimeInMicros(void)
+{
+ return (CARD64) GetTickCount() * 1000;
+}
#else
CARD32
GetTimeInMillis(void)
@@ -460,6 +465,28 @@ GetTimeInMillis(void)
X_GETTIMEOFDAY(&tv);
return (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
}
+
+CARD64
+GetTimeInMicros(void)
+{
+ struct timeval tv;
+#ifdef MONOTONIC_CLOCK
+ struct timespec tp;
+ static clockid_t clockid;
+
+ if (!clockid) {
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+ clockid = CLOCK_MONOTONIC;
+ else
+ clockid = ~0L;
+ }
+ if (clock_gettime(CLOCK_MONOTONIC, &tp) == 0)
+ return (CARD64) tp.tv_sec * (CARD64)1000000 + tp.tv_nsec / 1000;
+#endif
+
+ X_GETTIMEOFDAY(&tv);
+ return (CARD64) tv.tv_sec * (CARD64)1000000000 + (CARD64) tv.tv_usec * 1000;
+}
#endif
void