[prev in list] [next in list] [prev in thread] [next in thread]
List: freedesktop-xorg-devel
Subject: [PATCH 04/10] os: Add GetTimeInNanos
From: Keith Packard <keithp () keithp ! com>
Date: 2013-10-31 22:43:36
Message-ID: 1383259423-30406-5-git-send-email-keithp () keithp ! com
[Download RAW message or body]
64-bit higher resolution current time value.
Signed-off-by: Keith Packard <keithp@keithp.com>
---
include/os.h | 1 +
os/utils.c | 27 +++++++++++++++++++++++++++
2 files changed, 28 insertions(+)
diff --git a/include/os.h b/include/os.h
index c7108a5..3840ab9 100644
--- a/include/os.h
+++ b/include/os.h
@@ -165,6 +165,7 @@ extern void ListenOnOpenFD(int /* fd */ , int /* noxauth */ );
#endif
extern _X_EXPORT CARD32 GetTimeInMillis(void);
+extern _X_EXPORT CARD64 GetTimeInMicros(void);
extern _X_EXPORT void AdjustWaitForDelay(pointer /*waitTime */ ,
unsigned long /*newdelay */ );
diff --git a/os/utils.c b/os/utils.c
index 97c3125..995f62a 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
--
1.8.4.rc3
_______________________________________________
xorg-devel@lists.x.org: X.Org development
Archives: http://lists.x.org/archives/xorg-devel
Info: http://lists.x.org/mailman/listinfo/xorg-devel
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic