vcl/inc/unx/gtk/gtkdata.hxx |    2 +-
 vcl/unx/gtk3/gtkdata.cxx    |   37 +++++++++++++++++++++----------------
 2 files changed, 22 insertions(+), 17 deletions(-)

New commits:
commit 4d396956b06c80bd7ade3825ef1a9fe1e787488c
Author:     Hossein <hoss...@libreoffice.org>
AuthorDate: Fri Dec 17 10:35:49 2021 +0100
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Fri Dec 17 12:38:21 2021 +0100

    tdf#146225 Revert "Use g_get_real_time instead of g_get_current_time"
    
    This reverts commit 489d7298d2e609ee5900f05ba0064845a7a551ce and
    4812c8df39cb03b59d8c033005e8e9dc45a260dd.
    
    Change-Id: Ic537a605eedc39c6cbafab4c28a77d81edfa1e20
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/126998
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins

diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 5a5f00336c01..0c6b73cabadc 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -214,7 +214,7 @@ public:
     virtual void Stop() override;
     bool         Expired();
 
-    sal_uInt64    m_nTimeoutMS;
+    sal_uLong    m_nTimeoutMS;
 };
 
 class DocumentFocusListener final :
diff --git a/vcl/unx/gtk3/gtkdata.cxx b/vcl/unx/gtk3/gtkdata.cxx
index 7c64db06225e..861ae6e64743 100644
--- a/vcl/unx/gtk3/gtkdata.cxx
+++ b/vcl/unx/gtk3/gtkdata.cxx
@@ -641,22 +641,21 @@ extern "C" {
 
     struct SalGtkTimeoutSource {
         GSource      aParent;
-        gint64       aFireTime;
+        GTimeVal     aFireTime;
         GtkSalTimer *pInstance;
     };
 
     static void sal_gtk_timeout_defer( SalGtkTimeoutSource *pTSource )
     {
-        pTSource->aFireTime = g_get_real_time() + 
pTSource->pInstance->m_nTimeoutMS * 1000;
+        g_get_current_time( &pTSource->aFireTime );
+        g_time_val_add( &pTSource->aFireTime, 
pTSource->pInstance->m_nTimeoutMS * 1000 );
     }
 
     static gboolean sal_gtk_timeout_expired( SalGtkTimeoutSource *pTSource,
-                                             gint *nTimeoutMS, gint64 const 
pTimeNow )
+                                             gint *nTimeoutMS, GTimeVal const 
*pTimeNow )
     {
-        glong tv_sec = pTimeNow / 1000000;
-        glong tv_usec = pTimeNow - tv_sec * 1000000;
-        glong nDeltaSec = pTSource->aFireTime / 1000000 - tv_sec;
-        glong nDeltaUSec = pTSource->aFireTime - (nDeltaSec * 1000000) - 
tv_usec;
+        glong nDeltaSec = pTSource->aFireTime.tv_sec - pTimeNow->tv_sec;
+        glong nDeltaUSec = pTSource->aFireTime.tv_usec - pTimeNow->tv_usec;
         if( nDeltaSec < 0 || ( nDeltaSec == 0 && nDeltaUSec < 0) )
         {
             *nTimeoutMS = 0;
@@ -683,20 +682,22 @@ extern "C" {
     {
         SalGtkTimeoutSource *pTSource = reinterpret_cast<SalGtkTimeoutSource 
*>(pSource);
 
-        gint64 aTimeNow;
-        aTimeNow = g_get_real_time();
+        GTimeVal aTimeNow;
+        g_get_current_time( &aTimeNow );
 
-        return sal_gtk_timeout_expired( pTSource, nTimeoutMS, aTimeNow );
+        return sal_gtk_timeout_expired( pTSource, nTimeoutMS, &aTimeNow );
     }
 
     static gboolean sal_gtk_timeout_check( GSource *pSource )
     {
         SalGtkTimeoutSource *pTSource = reinterpret_cast<SalGtkTimeoutSource 
*>(pSource);
 
-        gint64 aTimeNow;
-        aTimeNow = g_get_real_time();
+        GTimeVal aTimeNow;
+        g_get_current_time( &aTimeNow );
 
-        return ( pTSource->aFireTime < aTimeNow );
+        return ( pTSource->aFireTime.tv_sec < aTimeNow.tv_sec ||
+                 ( pTSource->aFireTime.tv_sec == aTimeNow.tv_sec &&
+                   pTSource->aFireTime.tv_usec < aTimeNow.tv_usec ) );
     }
 
     static gboolean sal_gtk_timeout_dispatch( GSource *pSource, GSourceFunc, 
gpointer )
@@ -769,13 +770,17 @@ bool GtkSalTimer::Expired()
         return false;
 
     gint nDummy = 0;
-    gint64 aTimeNow;
-    aTimeNow = g_get_real_time();
-    return !!sal_gtk_timeout_expired( m_pTimeout, &nDummy, aTimeNow);
+    GTimeVal aTimeNow;
+    g_get_current_time( &aTimeNow );
+    return !!sal_gtk_timeout_expired( m_pTimeout, &nDummy, &aTimeNow);
 }
 
 void GtkSalTimer::Start( sal_uInt64 nMS )
 {
+    // glib is not 64bit safe in this regard.
+    assert( nMS <= G_MAXINT );
+    if ( nMS > G_MAXINT )
+        nMS = G_MAXINT;
     m_nTimeoutMS = nMS; // for restarting
     Stop(); // FIXME: ideally re-use an existing m_pTimeout
     m_pTimeout = create_sal_gtk_timeout( this );

Reply via email to