[Libreoffice-commits] core.git: Branch 'feature/priorities' - include/vcl vcl/source

Tobias Madl tobias.madl.dev at gmail.com
Wed Jan 21 05:06:25 PST 2015


 include/vcl/idle.hxx    |   51 ++++++++++++++++++++++++------------
 vcl/source/app/idle.cxx |   68 ++++++++++++------------------------------------
 2 files changed, 53 insertions(+), 66 deletions(-)

New commits:
commit 75d61d16fce70a53d250a0ef6b7df30b1fd329e6
Author: Tobias Madl <tobias.madl.dev at gmail.com>
Date:   Wed Jan 21 14:04:59 2015 +0100

    Idle: New enum system, comments
    
    Change-Id: I8ca272481e573bf3338c5c1b9873a39022928812

diff --git a/include/vcl/idle.hxx b/include/vcl/idle.hxx
index 0415575..6c40ca3 100644
--- a/include/vcl/idle.hxx
+++ b/include/vcl/idle.hxx
@@ -27,28 +27,47 @@
 struct ImplIdleData;
 struct ImplSVData;
 
-// The timemarks behind the priorities are need to change timer to idle. It is to convert
-// timeout values to priorities.
 enum class IdlePriority {
-    VCL_IDLE_PRIORITY_STARVATIONPROTECTION  = -1, // Do not use this for normal prioritizing!
-
-    VCL_IDLE_PRIORITY_HIGHEST               = 0,  // -> 0ms
-    VCL_IDLE_PRIORITY_HIGH                  = 1,  // -> 1ms
-    VCL_IDLE_PRIORITY_DEFAULT               = 1,  // -> 1ms
-    VCL_IDLE_PRIORITY_REPAINT               = 2,  // -> 30ms
-    VCL_IDLE_PRIORITY_RESIZE                = 3,  // -> 50ms
-    VCL_IDLE_PRIORITY_MEDIUM                = 3,  // -> 50ms
-    VCL_IDLE_PRIORITY_LOW                   = 4,  // -> 100ms
-    VCL_IDLE_PRIORITY_LOWER                 = 5,  // -> 200ms
-    VCL_IDLE_PRIORITY_LOWEST                = 6   // -> 400ms
+    VCL_IDLE_PRIORITY_HIGHEST,
+    VCL_IDLE_PRIORITY_HIGH,
+    VCL_IDLE_PRIORITY_REPAINT,
+    VCL_IDLE_PRIORITY_RESIZE,
+    VCL_IDLE_PRIORITY_MEDIUM,
+    VCL_IDLE_PRIORITY_LOW,
+    VCL_IDLE_PRIORITY_LOWER,
+    VCL_IDLE_PRIORITY_LOWEST
 };
 
+inline sal_Int32 convertToInt( IdlePriority ePriority )
+{
+    switch (ePriority)
+    {
+        case IdlePriority::VCL_IDLE_PRIORITY_HIGHEST:
+            return 0;
+        case IdlePriority::VCL_IDLE_PRIORITY_HIGH:
+            return 1;
+        case IdlePriority::VCL_IDLE_PRIORITY_REPAINT:
+            return 2;
+        case IdlePriority::VCL_IDLE_PRIORITY_RESIZE:
+            return 3;
+        case IdlePriority::VCL_IDLE_PRIORITY_MEDIUM:
+            return 3;
+        case IdlePriority::VCL_IDLE_PRIORITY_LOW:
+            return 4;
+        case IdlePriority::VCL_IDLE_PRIORITY_LOWER:
+            return 5;
+        case IdlePriority::VCL_IDLE_PRIORITY_LOWEST:
+            return 6;
+    }
+
+    return 42; // Should not happen
+}
 
 class VCL_DLLPUBLIC Idle
 {
 protected:
     ImplIdleData*   mpIdleData;         // Pointer to element in idle list
-    IdlePriority    mePriority;         // Idle priority ( maybe divergent to default)
+    sal_Int32       miPriority;         // Idle priority ( maybe divergent to default)
     IdlePriority    meDefaultPriority;  // Default idle priority
     bool            mbActive;           // Currently in the scheduler
     Link            maIdleHdl;          // Callback Link
@@ -61,7 +80,8 @@ public:
     virtual ~Idle();
 
     void SetPriority( IdlePriority ePriority );
-    IdlePriority GetPriority() const { return mePriority; }
+    void SetSchedulingPriority( sal_Int32 iPriority );
+    sal_Int32    GetPriority() const { return miPriority; }
     IdlePriority GetDefaultPriority() const { return meDefaultPriority; }
 
     /// Make it possible to associate a callback with this idle handler
@@ -79,7 +99,6 @@ public:
 
     Idle&          operator=( const Idle& rIdle );
     static void ImplDeInitIdle();
-    static void ImplIdleCallbackProc();
 
     /// Process all pending idle tasks ahead of time in priority order.
     static void ProcessAllIdleHandlers();
diff --git a/vcl/source/app/idle.cxx b/vcl/source/app/idle.cxx
index 37299de..cc92d36 100644
--- a/vcl/source/app/idle.cxx
+++ b/vcl/source/app/idle.cxx
@@ -26,17 +26,17 @@
 
 struct ImplIdleData
 {
-    ImplIdleData*   mpNext;      // Pointer to the next Instance
+    ImplIdleData*   mpNext;      // Pointer to the next element in list
     Idle*           mpIdle;      // Pointer to VCL Idle instance
-    bool            mbDelete;    // Was Idle deleted during Update()?
-    bool            mbInIdle;    // Are we in a idle handler?
+    bool            mbDelete;    // Destroy this idle?
+    bool            mbInIdle;    // Idle handler currently processed?
 
     void Invoke()
     {
         if (mbDelete || mbInIdle )
             return;
 
-        mpIdle->SetPriority(mpIdle->GetDefaultPriority());
+        mpIdle->SetSchedulingPriority(convertToInt(mpIdle->GetDefaultPriority()));
         mbDelete = true;
         mpIdle->mbActive = false;
 
@@ -65,49 +65,16 @@ struct ImplIdleData
                 // the current is the new most urgent. So starving is impossible.
                 if ( p->mpIdle->GetPriority() < pMostUrgent->mpIdle->GetPriority() )
                 {
-                    IncreasePriority(pMostUrgent->mpIdle);
+                    pMostUrgent->mpIdle->SetSchedulingPriority( pMostUrgent->mpIdle->GetPriority() - 1);
                     pMostUrgent = p;
                 }
                 else
-                    IncreasePriority(p->mpIdle);
+                    p->mpIdle->SetSchedulingPriority( p->mpIdle->GetPriority() - 1);
             }
         }
 
         return pMostUrgent;
     }
-
-    static void IncreasePriority( Idle *pIdle )
-    {
-        switch(pIdle->GetPriority())
-        {
-            // Increase priority based on their current priority;
-            // (so don't use VCL_IDLE_PRIORITY_STARVATIONPROTECTION for default-priority!)
-            case IdlePriority::VCL_IDLE_PRIORITY_STARVATIONPROTECTION:
-                break;
-            // If already highest priority -> extra state for starving tasks
-            case IdlePriority::VCL_IDLE_PRIORITY_HIGHEST:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_STARVATIONPROTECTION);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_HIGH:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_HIGHEST);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_REPAINT:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_HIGH);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_MEDIUM:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_REPAINT);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_LOW:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_MEDIUM);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_LOWER:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_LOW);
-                break;
-            case IdlePriority::VCL_IDLE_PRIORITY_LOWEST:
-                pIdle->SetPriority(IdlePriority::VCL_IDLE_PRIORITY_LOWER);
-                break;
-        }
-    }
 };
 
 void Idle::ImplDeInitIdle()
@@ -149,7 +116,7 @@ void Idle::ProcessAllIdleHandlers()
     pIdleData = pSVData->mpFirstIdleData;
     while ( pIdleData )
     {
-        // Was idle destroyed in the meantime?
+        // Should idle be released from scheduling?
         if ( pIdleData->mbDelete )
         {
             if ( pPrevIdleData )
@@ -172,11 +139,12 @@ void Idle::ProcessAllIdleHandlers()
 
 void Idle::SetPriority( IdlePriority ePriority )
 {
-    mePriority = ePriority;
-    // Was a new priority set before excecution?
-    // Then take it as default priority
-    if( !mbActive && meDefaultPriority == IdlePriority::VCL_IDLE_PRIORITY_DEFAULT )
-        meDefaultPriority = mePriority;
+    meDefaultPriority = ePriority;
+}
+
+void Idle::SetSchedulingPriority( sal_Int32 iPriority )
+{
+    miPriority = iPriority;
 }
 
 void Idle::DoIdle()
@@ -228,7 +196,7 @@ Idle& Idle::operator=( const Idle& rIdle )
         Stop();
 
     mbActive          = false;
-    mePriority        = rIdle.mePriority;
+    miPriority        = rIdle.miPriority;
     meDefaultPriority = rIdle.meDefaultPriority;
     maIdleHdl         = rIdle.maIdleHdl;
 
@@ -240,15 +208,15 @@ Idle& Idle::operator=( const Idle& rIdle )
 
 Idle::Idle():
     mpIdleData(NULL),
-    mePriority(IdlePriority::VCL_IDLE_PRIORITY_DEFAULT),
-    meDefaultPriority(IdlePriority::VCL_IDLE_PRIORITY_DEFAULT),
+    miPriority(convertToInt(IdlePriority::VCL_IDLE_PRIORITY_HIGH)),
+    meDefaultPriority(IdlePriority::VCL_IDLE_PRIORITY_HIGH),
     mbActive(false)
 {
 }
 
 Idle::Idle( const Idle& rIdle ):
     mpIdleData(NULL),
-    mePriority(rIdle.mePriority),
+    miPriority(rIdle.miPriority),
     meDefaultPriority(rIdle.meDefaultPriority),
     mbActive(false),
     maIdleHdl(rIdle.maIdleHdl)
@@ -265,4 +233,4 @@ Idle::~Idle()
         mpIdleData->mpIdle = NULL;
     }
 }
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
\ No newline at end of file
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list