[PATCH] Use clock_gettime instead of gettimeofday to have more preci...

Arnaud Versini (via Code Review) gerrit at gerrit.libreoffice.org
Fri May 10 05:26:08 PDT 2013


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3841

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/41/3841/1

Use clock_gettime instead of gettimeofday to have more precise time

Change-Id: I8e568368e7626789dee21d4823dbedec6257a231
---
M sal/osl/unx/time.c
1 file changed, 11 insertions(+), 5 deletions(-)



diff --git a/sal/osl/unx/time.c b/sal/osl/unx/time.c
index e613248..e499d85 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,20 @@
 
 sal_Bool SAL_CALL osl_getSystemTime(TimeValue* tv)
 {
-    struct timeval tp;
+    struct timespec tp;
+    int res;
 
-    /* FIXME: use higher resolution */
-    gettimeofday(&tp, NULL);
+    res = clock_gettime(CLOCK_REALTIME, &tp);
+
+    if (res != 0)
+    {
+        return sal_False;
+    }
 
     tv->Seconds = tp.tv_sec;
-    tv->Nanosec = tp.tv_usec * 1000;
+    tv->Nanosec = tp.tv_nsec;
 
-    return (sal_True);
+    return sal_True;
 }
 
 

-- 
To view, visit https://gerrit.libreoffice.org/3841
To unsubscribe, visit https://gerrit.libreoffice.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8e568368e7626789dee21d4823dbedec6257a231
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: master
Gerrit-Owner: Arnaud Versini <arnaud.versini at gmail.com>



More information about the LibreOffice mailing list