From c85493b6a8033f5bab937e970f824d3a4bcbc790 Mon Sep 17 00:00:00 2001 From: Arnaud Versini Date: Thu, 9 May 2013 14:45:18 +0200 Subject: 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 Tested-by: Norbert Thiebaud --- sal/osl/unx/time.c | 22 +++++++++++++++++++--- 1 file 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 #include +#include /* 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; } -- cgit