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/4002

To pull it, you can do:

    git pull ssh://gerrit.libreoffice.org:29418/core refs/changes/02/4002/1

Revert "Thread-safe version of osl_getGlobalTime"

This reverts commit d8d55787b81cdc955b73c8befa4ab608f46e32aa.
and 9b76439dff638d6fd773f2b63c377c2124810a39

as the change failed to work correctly on MacOSX causing a CPU-Loop
in UpdateCheckThread::run()

Change-Id: Ide86a5b7dce9550bbc15dfe691d4ed6199a88cc3
---
M sal/osl/unx/salinit.cxx
M sal/osl/unx/time.c
M sal/osl/w32/salinit.cxx
M sal/osl/w32/time.c
4 files changed, 31 insertions(+), 83 deletions(-)



diff --git a/sal/osl/unx/salinit.cxx b/sal/osl/unx/salinit.cxx
index c71c6a3..327ca0e 100644
--- a/sal/osl/unx/salinit.cxx
+++ b/sal/osl/unx/salinit.cxx
@@ -38,9 +38,6 @@
 
 extern "C" {
 
-//From time.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
@@ -67,7 +64,6 @@
         close(fd);
     }
 #endif
-    sal_initGlobalTimer();
 #if HAVE_SYSLOG_H
     const char *use_syslog = getenv("SAL_LOG_SYSLOG");
     sal_use_syslog = use_syslog != NULL && !strcmp(use_syslog, "1");
diff --git a/sal/osl/unx/time.c b/sal/osl/unx/time.c
index b71dd7d..c99036b 100644
--- a/sal/osl/unx/time.c
+++ b/sal/osl/unx/time.c
@@ -23,15 +23,9 @@
 #include <osl/diagnose.h>
 #include <osl/time.h>
 #include <time.h>
-#include <assert.h>
-#include <unistd.h>
-
-#if defined(MACOSX) || defined(IOS)
-#include <mach/mach_time.h>
-#endif
 
 /* FIXME: detection should be done in configure script */
-#if defined(MACOSX) || defined(IOS) || defined(FREEBSD) || defined(NETBSD) || \
+#if defined(MACOSX) || defined(FREEBSD) || defined(NETBSD) || \
     defined(LINUX) || defined(OPENBSD) || defined(DRAGONFLY)
 #define STRUCT_TM_HAS_GMTOFF 1
 
@@ -39,36 +33,20 @@
 #define HAS_ALTZONE 1
 #endif
 
-#if defined(MACOSX) || defined(IOS)
-typedef sal_uInt64 osl_time_t;
-static double adjust_time_factor;
-#else
-#if defined(_POSIX_TIMERS)
-#define USE_CLOCK_GETTIME
-typedef struct timespec osl_time_t;
-#else
-typedef struct timeval osl_time_t;
-#endif
-#endif
-static osl_time_t startTime;
-
-
 /*--------------------------------------------------
  * osl_getSystemTime
  *-------------------------------------------------*/
 
 sal_Bool SAL_CALL osl_getSystemTime(TimeValue* tv)
 {
-#if defined(MACOSX) || defined(IOS)
-    double diff = (double)(mach_absolute_time() - startTime) * adjust_time_factor;
-    tv->Seconds = (sal_uInt32)diff;
-    tv->Nanosec = (sal_uInt32)((diff - tv->Seconds) * 1e9);
-#else
     int res;
-    osl_time_t tp;
-#if defined(USE_CLOCK_GETTIME)
+#if defined(LINUX)
+    struct timespec tp;
+
     res = clock_gettime(CLOCK_REALTIME, &tp);
 #else
+    struct timeval tp;
+
     res = gettimeofday(&tp, NULL);
 #endif
 
@@ -78,12 +56,12 @@
     }
 
     tv->Seconds = tp.tv_sec;
-    #if defined(USE_CLOCK_GETTIME)
+    #if defined(LINUX)
     tv->Nanosec = tp.tv_nsec;
     #else
     tv->Nanosec = tp.tv_usec * 1000;
     #endif
-#endif
+
     return sal_True;
 }
 
@@ -275,54 +253,28 @@
     return sal_False;
 }
 
-void sal_initGlobalTimer()
-{
-#if defined(MACOSX) || defined(IOS)
-  mach_timebase_info_data_t timebase;
-  mach_timebase_info(&timebase);
-  adjust_time_factor = 1e-9 * (double)timebase.numer / (double)(timebase.denom);
-  startTime = mach_absolute_time();
-#else /* ! (MACOSX || IOS) */
-  int res;
-#if defined(USE_CLOCK_GETTIME)
-  res = clock_gettime(CLOCK_REALTIME, &startTime);
-#else /* Ndef USE_CLOCK_GETTIME */
-  res = gettimeofday( &startTime, NULL );
-#endif /* NDef USE_CLOCK_GETTIME */
-  assert(res == 0);
-  (void) res;
-#endif /* ! (MACOSX || IOS) */
-}
+
+
+static struct timeval startTime;
+static sal_Bool bGlobalTimer = sal_False;
 
 sal_uInt32 SAL_CALL osl_getGlobalTimer()
 {
-    sal_uInt32 nSeconds;
+  struct timeval currentTime;
+  sal_uInt32 nSeconds;
 
-#if defined(MACOSX) || defined(IOS)
-    double diff = (double)(mach_absolute_time() - startTime) * adjust_time_factor * 1000;
-    nSeconds = (sal_uInt32)diff;
-#else
-    osl_time_t currentTime;
-    int res;
+  // FIXME: not thread safe !!
+  if ( bGlobalTimer == sal_False )
+  {
+      gettimeofday( &startTime, NULL );
+      bGlobalTimer=sal_True;
+  }
 
-#if defined(USE_CLOCK_GETTIME)
-    res = clock_gettime(CLOCK_REALTIME, &currentTime);
-#else
-    res = gettimeofday( &currentTime, NULL );
-#endif
-    assert(res == 0);
+  gettimeofday( &currentTime, NULL );
 
-    if (res != 0)
-        return 0;
+  nSeconds = (sal_uInt32)( currentTime.tv_sec - startTime.tv_sec );
 
-    nSeconds = (sal_uInt32)( currentTime.tv_sec - startTime.tv_sec );
-#if defined(USE_CLOCK_GETTIME)
-    nSeconds = ( nSeconds * 1000 ) + (long) (( currentTime.tv_nsec - startTime.tv_nsec) / 1000000 
);
-#else
-    nSeconds = ( nSeconds * 1000 ) + (long) (( currentTime.tv_usec - startTime.tv_usec) / 1000 );
-#endif
-#endif
-    return nSeconds;
+  return ( nSeconds * 1000 ) + (long) (( currentTime.tv_usec - startTime.tv_usec) / 1000 );
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sal/osl/w32/salinit.cxx b/sal/osl/w32/salinit.cxx
index 3eb9290..e392f4a 100644
--- a/sal/osl/w32/salinit.cxx
+++ b/sal/osl/w32/salinit.cxx
@@ -31,9 +31,6 @@
 extern "C" {
 #endif
 
-//From time.c
-void sal_initGlobalTimer();
-
 // _set_invalid_parameter_handler appears unavailable with MinGW:
 #if defined _MSC_VER
 namespace {
@@ -55,7 +52,6 @@
 
 void sal_detail_initialize(int argc, char ** argv)
 {
-    sal_initGlobalTimer();
     // SetProcessDEPPolicy(PROCESS_DEP_ENABLE);
     // SetDllDirectoryW(L"");
     // SetSearchPathMode(
diff --git a/sal/osl/w32/time.c b/sal/osl/w32/time.c
index fc8855b..49f33c2 100644
--- a/sal/osl/w32/time.c
+++ b/sal/osl/w32/time.c
@@ -184,17 +184,21 @@
     return sal_False;
 }
 
+
 static struct _timeb startTime;
-void sal_initGlobalTimer()
-{
-    _ftime( &startTime );
-}
+static sal_Bool bGlobalTimer = sal_False;
 
 sal_uInt32 SAL_CALL osl_getGlobalTimer(void)
 {
   struct _timeb currentTime;
   sal_uInt32 nSeconds;
 
+  if ( bGlobalTimer == sal_False )
+  {
+      _ftime( &startTime );
+      bGlobalTimer=sal_True;
+  }
+
   _ftime( &currentTime );
 
   nSeconds = (sal_uInt32)( currentTime.time - startTime.time );

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

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ide86a5b7dce9550bbc15dfe691d4ed6199a88cc3
Gerrit-PatchSet: 1
Gerrit-Project: core
Gerrit-Branch: libreoffice-4-1
Gerrit-Owner: Norbert Thiebaud <nthiebaud@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.