summaryrefslogtreecommitdiff
path: root/sal/osl
diff options
context:
space:
mode:
authorArnaud Versini <arnaud.versini@gmail.com>2013-05-09 14:45:18 +0200
committerNorbert Thiebaud <nthiebaud@gmail.com>2013-05-13 16:59:26 +0000
commitc85493b6a8033f5bab937e970f824d3a4bcbc790 (patch)
tree6633bbacbdb670d5c7abd12091c5640fb786d5a1 /sal/osl
parente84209af1104ff7d94e69324d946c6d8113e0066 (diff)
Use clock_gettime instead of gettimeofday to have more precise time
Change-Id: I8e568368e7626789dee21d4823dbedec6257a231 Reviewed-on: https://gerrit.libreoffice.org/3841 Reviewed-by: Norbert Thiebaud <nthiebaud@gmail.com> Tested-by: Norbert Thiebaud <nthiebaud@gmail.com>
Diffstat (limited to 'sal/osl')
-rw-r--r--sal/osl/unx/time.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/sal/osl/unx/time.c b/sal/osl/unx/time.c
index e613248914b3..c99036babc67 100644
--- a/sal/osl/unx/time.c
+++ b/sal/osl/unx/time.c
@@ -22,6 +22,7 @@
#include <osl/diagnose.h>
#include <osl/time.h>
+#include <time.h>
/* FIXME: detection should be done in configure script */
#if defined(MACOSX) || defined(FREEBSD) || defined(NETBSD) || \
@@ -38,15 +39,30 @@
sal_Bool SAL_CALL osl_getSystemTime(TimeValue* tv)
{
+ int res;
+#if defined(LINUX)
+ struct timespec tp;
+
+ res = clock_gettime(CLOCK_REALTIME, &tp);
+#else
struct timeval tp;
- /* FIXME: use higher resolution */
- gettimeofday(&tp, NULL);
+ res = gettimeofday(&tp, NULL);
+#endif
+
+ if (res != 0)
+ {
+ return sal_False;
+ }
tv->Seconds = tp.tv_sec;
+ #if defined(LINUX)
+ tv->Nanosec = tp.tv_nsec;
+ #else
tv->Nanosec = tp.tv_usec * 1000;
+ #endif
- return (sal_True);
+ return sal_True;
}