Date: prev next · Thread: first prev next last
2013 Archives by date, by thread · List index


Hi,

I have submitted a patch for review:

    https://gerrit.libreoffice.org/3960

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/60/3960/1

Multi threaded version of osl_getGlobalTime on Unix

Change-Id: Ibb9d23780600437f607d866ff3d396b96879245d
---
M sal/osl/unx/salinit.cxx
M sal/osl/unx/time.c
2 files changed, 27 insertions(+), 8 deletions(-)



diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index 327ca0e..b33e5f3 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -38,6 +38,8 @@
 
 extern "C" {
 
+void sal_initGlobalTimer();
+
 void sal_detail_initialize(int argc, char ** argv) {
 #if defined MACOSX
     // On Mac OS X, soffice can restart itself via exec (see restartOnMac in
diff --git a/sal/osl/unx/time.c b/sal/osl/unx/time.c
index c99036b..1516cd9 100644
--- a/sal/osl/unx/time.c
+++ b/sal/osl/unx/time.c
@@ -253,22 +253,37 @@
     return sal_False;
 }
 
+#if defined(LINUX)
 
+void sal_initGlobalTimer() {}
+
+sal_uInt32 SAL_CALL osl_getGlobalTimer()
+{
+    struct timespec currentTime;
+    int res;
+
+    res = clock_gettime(CLOCK_PROCESS_CPUTIME_ID , NULL);
+    if (res != 0)
+    {
+       return 0;
+    }
+
+    return currentTime.tv_sec + (currentTime.tv_nsec / 1000);
+}
+
+#else
 
 static struct timeval startTime;
-static sal_Bool bGlobalTimer = sal_False;
+
+void sal_initGlobalTimer()
+{
+    gettimeofday( &startTime, NULL );
+}
 
 sal_uInt32 SAL_CALL osl_getGlobalTimer()
 {
   struct timeval currentTime;
   sal_uInt32 nSeconds;
-
-  // FIXME: not thread safe !!
-  if ( bGlobalTimer == sal_False )
-  {
-      gettimeofday( &startTime, NULL );
-      bGlobalTimer=sal_True;
-  }
 
   gettimeofday( &currentTime, NULL );
 
@@ -277,4 +292,6 @@
   return ( nSeconds * 1000 ) + (long) (( currentTime.tv_usec - startTime.tv_usec) / 1000 );
 }
 
+#endif
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

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

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


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.