[Libreoffice-commits] .: 2 commits - g vcl/inc vcl/unx

Michael Meeks michael at kemper.freedesktop.org
Tue Oct 25 08:27:01 PDT 2011


 g                           |   26 ++++++-
 vcl/inc/unx/gtk/gtkdata.hxx |    2 
 vcl/unx/gtk/app/gtkdata.cxx |  162 ++++++++++++++++++++++++++++++++++----------
 vcl/unx/gtk/app/gtkinst.cxx |   30 +-------
 4 files changed, 157 insertions(+), 63 deletions(-)

New commits:
commit 232c6f1309bb73cc6516c58da749f64ce3668932
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Tue Oct 25 16:17:40 2011 +0100

    gtk3: cleanup timeout source, to avoid annoying warnings with old glibs

diff --git a/vcl/inc/unx/gtk/gtkdata.hxx b/vcl/inc/unx/gtk/gtkdata.hxx
index 8b87eb2..ff4d104 100644
--- a/vcl/inc/unx/gtk/gtkdata.hxx
+++ b/vcl/inc/unx/gtk/gtkdata.hxx
@@ -82,7 +82,7 @@ inline void widget_set_can_default(GtkWidget *widget, gboolean can_default)
 
 class GtkSalTimer : public SalTimer
 {
-    GSource *m_pTimeout;
+    struct SalGtkTimeoutSource *m_pTimeout;
 public:
     GtkSalTimer();
     ~GtkSalTimer();
diff --git a/vcl/unx/gtk/app/gtkdata.cxx b/vcl/unx/gtk/app/gtkdata.cxx
index b50f859..4599ec4 100644
--- a/vcl/unx/gtk/app/gtkdata.cxx
+++ b/vcl/unx/gtk/app/gtkdata.cxx
@@ -778,8 +778,125 @@ bool GtkData::ErrorTrapPop( bool bIgnoreError )
     return gdk_error_trap_pop () != 0;
 }
 
+extern "C" {
+
+    struct SalGtkTimeoutSource {
+        GSource      aParent;
+        GTimeVal     aFireTime;
+        GtkSalTimer *pInstance;
+    };
+
+    static void sal_gtk_timeout_defer( SalGtkTimeoutSource *pTSource )
+    {
+        g_source_get_current_time( (GSource *) pTSource, &pTSource->aFireTime );
+        g_time_val_add( &pTSource->aFireTime, pTSource->pInstance->m_nTimeoutMS * 1000 );
+    }
+
+    static gboolean sal_gtk_timeout_expired( SalGtkTimeoutSource *pTSource,
+                                             gint *nTimeoutMS, GTimeVal *pTimeNow )
+    {
+        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;
+            return TRUE;
+        }
+        if( nDeltaUSec < 0 )
+        {
+            nDeltaUSec += 1000000;
+            nDeltaSec -= 1;
+        }
+        // if the clock changes backwards we need to cope ...
+        if( (unsigned long) nDeltaSec > 1 + ( pTSource->pInstance->m_nTimeoutMS / 1000 ) )
+        {
+            sal_gtk_timeout_defer( pTSource );
+            return TRUE;
+        }
+
+        *nTimeoutMS = MIN( G_MAXINT, ( nDeltaSec * 1000 + (nDeltaUSec + 999) / 1000 ) );
+
+        return *nTimeoutMS == 0;
+    }
+
+    static gboolean sal_gtk_timeout_prepare( GSource *pSource, gint *nTimeoutMS )
+    {
+        SalGtkTimeoutSource *pTSource = (SalGtkTimeoutSource *)pSource;
+
+        GTimeVal aTimeNow;
+        g_source_get_current_time( pSource, &aTimeNow );
+
+        return sal_gtk_timeout_expired( pTSource, nTimeoutMS, &aTimeNow );
+    }
+
+    static gboolean sal_gtk_timeout_check( GSource *pSource )
+    {
+        SalGtkTimeoutSource *pTSource = (SalGtkTimeoutSource *)pSource;
+
+        GTimeVal aTimeNow;
+        g_source_get_current_time( pSource, &aTimeNow );
+
+        if( pTSource->aFireTime.tv_sec > aTimeNow.tv_sec )
+            return FALSE;
+        if( pTSource->aFireTime.tv_sec < aTimeNow.tv_sec )
+            return TRUE;
+        if( pTSource->aFireTime.tv_usec < aTimeNow.tv_usec )
+            return FALSE;
+        return TRUE;
+    }
+
+    static gboolean sal_gtk_timeout_dispatch( GSource *pSource, GSourceFunc, gpointer )
+    {
+        SalGtkTimeoutSource *pTSource = (SalGtkTimeoutSource *)pSource;
+
+        if( !pTSource->pInstance )
+            return FALSE;
+
+        SalData *pSalData = GetSalData();
+
+        osl::SolarGuard aGuard( pSalData->m_pInstance->GetYieldMutex() );
+
+        sal_gtk_timeout_defer( pTSource );
+
+        ImplSVData* pSVData = ImplGetSVData();
+        if( pSVData->mpSalTimer )
+            pSVData->mpSalTimer->CallCallback();
+
+        return TRUE;
+    }
+
+    static GSourceFuncs sal_gtk_timeout_funcs =
+    {
+        sal_gtk_timeout_prepare,
+        sal_gtk_timeout_check,
+        sal_gtk_timeout_dispatch,
+        NULL, NULL, NULL
+    };
+}
+
+static SalGtkTimeoutSource *
+create_sal_gtk_timeout( GtkSalTimer *pTimer )
+{
+  GSource *pSource = g_source_new( &sal_gtk_timeout_funcs, sizeof( SalGtkTimeoutSource ) );
+  SalGtkTimeoutSource *pTSource = (SalGtkTimeoutSource *)pSource;
+  pTSource->pInstance = pTimer;
+
+  // #i36226# timers should be executed with lower priority
+  // than XEvents like in generic plugin
+  g_source_set_priority( pSource, G_PRIORITY_LOW );
+  g_source_set_can_recurse( pSource, TRUE );
+  g_source_set_callback( pSource,
+                         /* unused dummy */ g_idle_remove_by_data,
+                         NULL, NULL );
+  g_source_attach( pSource, g_main_context_default() );
+
+  sal_gtk_timeout_defer( pTSource );
+
+  return pTSource;
+}
+
 GtkSalTimer::GtkSalTimer()
-    : m_pTimeout( 0 )
+    : m_pTimeout( NULL )
 {
 }
 
@@ -794,54 +911,27 @@ bool GtkSalTimer::Expired()
 {
     if( !m_pTimeout )
         return false;
-    GSourceFuncs *pKlass = m_pTimeout->source_funcs;
-    gint timeout = 0;
-    if( pKlass && pKlass->prepare )
-        return !!pKlass->prepare( m_pTimeout, &timeout );
-    else
-        return false;
-}
-
-extern "C"
-{
-    gboolean call_timeoutFn( gpointer pData )
-    {
-        GtkSalTimer *pTimer = (GtkSalTimer *)pData;
-        SalData *pSalData = GetSalData();
-
-        osl::SolarGuard aGuard( pSalData->m_pInstance->GetYieldMutex() );
-
-        pTimer->Start( pTimer->m_nTimeoutMS );
-
-        ImplSVData* pSVData = ImplGetSVData();
-        if( pSVData->mpSalTimer )
-            pSVData->mpSalTimer->CallCallback();
 
-        return FALSE;
-    }
+    gint nDummy = 0;
+    GTimeVal aTimeNow;
+    g_get_current_time( &aTimeNow );
+    return !!sal_gtk_timeout_expired( m_pTimeout, &nDummy, &aTimeNow);
 }
 
 void GtkSalTimer::Start( sal_uLong nMS )
 {
     m_nTimeoutMS = nMS; // for restarting
     Stop();
-
-    m_pTimeout = g_timeout_source_new (m_nTimeoutMS);
-    // #i36226# timers should be executed with lower priority
-    // than XEvents like in generic plugin
-    g_source_set_priority( m_pTimeout, G_PRIORITY_LOW );
-    g_source_set_can_recurse (m_pTimeout, TRUE);
-    g_source_set_callback (m_pTimeout, call_timeoutFn,
-                           (gpointer) this, NULL);
-    g_source_attach (m_pTimeout, g_main_context_default ());
+    m_pTimeout = create_sal_gtk_timeout( this );
 }
 
 void GtkSalTimer::Stop()
 {
     if( m_pTimeout )
     {
-        g_source_destroy( m_pTimeout );
-        g_source_unref( m_pTimeout );
+        g_source_destroy( (GSource *)m_pTimeout );
+        g_source_unref( (GSource *)m_pTimeout );
+        m_pTimeout = NULL;
     }
 }
 
diff --git a/vcl/unx/gtk/app/gtkinst.cxx b/vcl/unx/gtk/app/gtkinst.cxx
index 9049419..1f9f1b1 100644
--- a/vcl/unx/gtk/app/gtkinst.cxx
+++ b/vcl/unx/gtk/app/gtkinst.cxx
@@ -584,32 +584,12 @@ void GtkInstance::Yield( bool bWait, bool bHandleAllCurrentEvents )
 
 bool GtkInstance::IsTimerExpired()
 {
-    gint nPriority;
-    bool bRet = false;
-    GMainContext *pCtx = g_main_context_default();
+    for( std::vector<GtkSalTimer *>::iterator it = m_aTimers.begin();
+         it != m_aTimers.end(); ++it )
+        if( (*it)->Expired() )
+            return true;
 
-    if( !g_main_context_acquire( pCtx ) )
-        return false; // some other thread is waiting still ...
-
-    // FIXME: we need to re-work this to do our own timeouts to avoid
-    // warnings from older glib's about poll_waiting etc.
-
-    // sets GMainContext's time_is_fresh to FALSE
-    if( g_main_context_prepare( pCtx, &nPriority ) )
-    {
-        for( std::vector<GtkSalTimer *>::iterator it = m_aTimers.begin();
-             it != m_aTimers.end(); ++it )
-        {
-            if( (*it)->Expired() )
-            {
-                bRet = true;
-                break;
-            }
-        }
-    }
-    g_main_context_release( pCtx );
-
-    return bRet;
+    return false;
 }
 
 bool GtkInstance::AnyInput( sal_uInt16 nType )
commit 4d2803d706c8e3036bc85a9c3a1935c7fc9df0fd
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Tue Oct 25 13:20:58 2011 +0100

    initial cut at 'last working' feature to help windows builders

diff --git a/g b/g
index e5a91f3..796d843 100755
--- a/g
+++ b/g
@@ -14,7 +14,10 @@ if [ "$#" -eq "0" ] ; then
     echo "   -s         Silent - do not report the repo names."
     echo "   -1         report the repos name on the first line of the output as <repo>:"
     echo "   -z         just to some house cleaning (hooks mostly). this is a stand-alone option as in ./g -z"
-    echo "   --set-push-user [username] re-write an existing tree's config with an fd.o commit account name"
+    echo "   --set-push-user     [username] re-write an existing tree's config with an fd.o commit account name"
+    echo "   --last-working      checks out the last known working build (useful for windows)";
+    echo "   --set-last-working  adds a note denoting a working build";
+    echo "   --push-notes        pushes all notes";
     exit $?
 fi
 
@@ -105,6 +108,10 @@ COMMAND="$1"
 PAGER=
 RELATIVIZE=1
 PUSH_ALL=
+PUSH_USER=
+PUSH_NOTES=
+LAST_WORKING=
+SET_LAST_WORKING=
 ALLOW_EMPTY=
 KEEP_GOING=0
 REPORT_REPOS=1
@@ -123,6 +130,12 @@ while [ "${COMMAND:0:1}" = "-" ] ; do
 	    shift
 	    PUSH_USER="$1"
 	    ;;
+	--last-working) LAST_WORKING=1
+	    ;;
+	--set-last-working) SET_LAST_WORKING=1
+	    ;;
+	--push-notes) PUSH_NOTES=1
+	    ;;
 	-z)
 	    DO_HOOK_REFRESH=true
 	    postprocess 0
@@ -226,6 +239,17 @@ for REPO in $DIRS ; do
     if [ -d "$DIR" -a "z$PUSH_USER" != "z" ]; then
        echo "setting up push url for $DIR"
 	   (cd $DIR && git config remote.origin.pushurl "ssh://${PUSH_USER}@git.freedesktop.org/git/libreoffice/${REPO}")
+    elif [ -d "$DIR" -a "z$LAST_WORKING" != "z" ]; then
+       echo "fetching notes for $REPO ..."
+       (cd $DIR && git fetch origin 'refs/notes/*:refs/notes/*')
+       # FIXME: we need to grep the git log for a known good note name...
+    elif [ -d "$DIR" -a "z$SET_LAST_WORKING" != "z" ]; then
+       echo "fetching notes for $REPO ..."
+       (cd $DIR && git fetch origin 'refs/notes/*:refs/notes/*')
+       (cd $DIR && git note add -m 'win32 working build')
+    elif [ -d "$DIR" -a "z$PUSH_NOTES" != "z" ]; then
+       echo "pushing notes for $REPO ..."
+       (cd $DIR && git push origin 'refs/notes/*:refs/notes/*')
     elif [ \( -d "$DIR" -a -d "$DIR"/.git \) -o \( "$COMMAND" = "clone" \) ] ; then
         (
             # executed in a subshell


More information about the Libreoffice-commits mailing list