[Libreoffice-commits] core.git: sw/inc sw/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Mon Aug 27 18:31:20 UTC 2018


 sw/inc/IDocumentTimerAccess.hxx             |    9 ++++--
 sw/source/core/doc/DocumentTimerManager.cxx |   39 +++++++++++-----------------
 sw/source/core/inc/DocumentTimerManager.hxx |    7 ++---
 3 files changed, 25 insertions(+), 30 deletions(-)

New commits:
commit 107f0e6dba57a5b27366a35a5cdb184079546df0
Author:     Jan-Marek Glogowski <glogow at fbihome.de>
AuthorDate: Fri Aug 24 18:31:35 2018 +0200
Commit:     Jan-Marek Glogowski <glogow at fbihome.de>
CommitDate: Mon Aug 27 20:30:57 2018 +0200

    tdf#119458 fix sw background Idle state handling
    
    Starting the SwDocIdle in StartIdeling() just reintroduces the
    bug fixed in commit 401cba4c20fb ("tdf#116370 cleanup Writer idle
    job handing"), so trading one bug for the other.
    
    For the real solution we have to handle two states:
    1. The SwDocIdle being active
    2. The SwDocIdle being blocked
    
    For the first state we can just use the active state of the Idle
    itself. Since it's not a AutoIdle, it will be turned of, if
    invoked. Either some Idle handler will want to be run it again or
    some other thread might start it again, if needed.
    Since we're now tracking the wanted Idle state via the active task
    flag, we can drop the explicit mbStartIdleTimer handling.
    
    As a result of the first change, we can't stop the Idle anymore
    when blocking it. But the Idle itself checks its ready state via
    IsDocIdle() in its UpdateMinPeriod function, so we have to add
    the blocking state to IsDocIdle().
    
    Change-Id: I33017a8e07208a6a3bce761cc899ac3ca944cd61
    Reviewed-on: https://gerrit.libreoffice.org/59586
    Tested-by: Jenkins
    Reviewed-by: Jan-Marek Glogowski <glogow at fbihome.de>

diff --git a/sw/inc/IDocumentTimerAccess.hxx b/sw/inc/IDocumentTimerAccess.hxx
index 1ed8679c00ac..f3e2738485af 100644
--- a/sw/inc/IDocumentTimerAccess.hxx
+++ b/sw/inc/IDocumentTimerAccess.hxx
@@ -21,7 +21,7 @@
 #define INCLUDED_SW_INC_IDOCUMENTTIMERACCESS_HXX
 
 /**
- * Handle the background job of the Writer document.
+ * Handle the background jobs of a Writer document.
  *
  * Initially it's disabled and unblocked.
  *
@@ -34,7 +34,9 @@ class IDocumentTimerAccess
 {
 public:
     /**
-     * Start the idle job depending on the block count.
+     * Start the idle task.
+     *
+     * Depends on the block count and various document states.
      */
     virtual void StartIdling() = 0;
 
@@ -47,13 +49,14 @@ public:
      * Increment block count.
      *
      * Prevents further background idle processing.
+     * This doesn't guarantee the Idle task is not currently running!
      */
     virtual void BlockIdling() = 0;
 
     /**
      * Decrement block count.
      *
-     * May start the idle job.
+     * May re-start the idle task, if active.
      */
     virtual void UnblockIdling() = 0;
 
diff --git a/sw/source/core/doc/DocumentTimerManager.cxx b/sw/source/core/doc/DocumentTimerManager.cxx
index 205e5992e59c..6195b8fdf961 100644
--- a/sw/source/core/doc/DocumentTimerManager.cxx
+++ b/sw/source/core/doc/DocumentTimerManager.cxx
@@ -38,46 +38,39 @@ namespace sw
 {
 
 DocumentTimerManager::DocumentTimerManager( SwDoc& i_rSwdoc ) : m_rDoc( i_rSwdoc ),
-                                                                mbStartIdleTimer( false ),
-                                                                mIdleBlockCount( 0 ),
-                                                                maDocIdle( i_rSwdoc )
+                                                                m_nIdleBlockCount( 0 ),
+                                                                m_aDocIdle( i_rSwdoc )
 {
-    maDocIdle.SetPriority( TaskPriority::LOWEST );
-    maDocIdle.SetInvokeHandler( LINK( this, DocumentTimerManager, DoIdleJobs) );
-    maDocIdle.SetDebugName( "sw::DocumentTimerManager maDocIdle" );
+    m_aDocIdle.SetPriority(TaskPriority::LOWEST);
+    m_aDocIdle.SetInvokeHandler(LINK( this, DocumentTimerManager, DoIdleJobs));
+    m_aDocIdle.SetDebugName("sw::DocumentTimerManager m_aDocIdle");
 }
 
 void DocumentTimerManager::StartIdling()
 {
-    if( !mIdleBlockCount )
-    {
-        mbStartIdleTimer = false;
-        maDocIdle.Start();
-    }
-    else
-        mbStartIdleTimer = true;
+    if (!m_aDocIdle.IsActive())
+        m_aDocIdle.Start();
 }
 
 void DocumentTimerManager::StopIdling()
 {
-    mbStartIdleTimer = false;
-    maDocIdle.Stop();
+    m_aDocIdle.Stop();
 }
 
 void DocumentTimerManager::BlockIdling()
 {
-    maDocIdle.Stop();
-    ++mIdleBlockCount;
+    assert(SAL_MAX_UINT32 != m_nIdleBlockCount);
+    ++m_nIdleBlockCount;
 }
 
 void DocumentTimerManager::UnblockIdling()
 {
-    --mIdleBlockCount;
-    if( !mIdleBlockCount && mbStartIdleTimer && !maDocIdle.IsActive() )
-    {
-        mbStartIdleTimer = false;
-        maDocIdle.Start();
-    }
+    assert(0 != m_nIdleBlockCount);
+    --m_nIdleBlockCount;
+
+    // kick the active idle, if it's not anymore blocked by IsDocIdle()
+    if (m_aDocIdle.IsActive() && IsDocIdle())
+        m_aDocIdle.Start();
 }
 
 DocumentTimerManager::IdleJob DocumentTimerManager::GetNextIdleJob() const
diff --git a/sw/source/core/inc/DocumentTimerManager.hxx b/sw/source/core/inc/DocumentTimerManager.hxx
index 214c0f626a75..e04e0602cc4f 100644
--- a/sw/source/core/inc/DocumentTimerManager.hxx
+++ b/sw/source/core/inc/DocumentTimerManager.hxx
@@ -66,14 +66,13 @@ private:
 
     SwDoc& m_rDoc;
 
-    bool mbStartIdleTimer; //< idle timer mode start/stop
-    sal_Int32 mIdleBlockCount;
-    SwDocIdle maDocIdle;
+    sal_uInt32 m_nIdleBlockCount; ///< Don't run the Idle, if > 0
+    SwDocIdle m_aDocIdle;
 };
 
 inline bool DocumentTimerManager::IsDocIdle() const
 {
-    return( GetNextIdleJob() != IdleJob::Busy );
+    return ((0 == m_nIdleBlockCount) && (GetNextIdleJob() != IdleJob::Busy));
 }
 
 }


More information about the Libreoffice-commits mailing list