[Libreoffice-commits] core.git: slideshow/source

Luboš Luňák (via logerrit) logerrit at kemper.freedesktop.org
Mon Oct 5 17:43:52 UTC 2020


 slideshow/source/engine/slideshowimpl.cxx |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

New commits:
commit d3792300afec9c9cb8751cae5b46e8f9198214b4
Author:     Luboš Luňák <l.lunak at collabora.com>
AuthorDate: Mon Oct 5 13:07:18 2020 +0200
Commit:     Luboš Luňák <l.lunak at collabora.com>
CommitDate: Mon Oct 5 19:43:15 2020 +0200

    try not to hog the CPU during slideshow animations
    
    Try to sleep for most of the busy-waiting loop. Seeing this CPU
    usage is annoying when profiling.
    
    Change-Id: Ia01b547b28a22ffcb0e841ea582c93891cf1c5c5
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/103960
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Luboš Luňák <l.lunak at collabora.com>

diff --git a/slideshow/source/engine/slideshowimpl.cxx b/slideshow/source/engine/slideshowimpl.cxx
index ba4d17cd6c1d..3bfee3cb88ba 100644
--- a/slideshow/source/engine/slideshowimpl.cxx
+++ b/slideshow/source/engine/slideshowimpl.cxx
@@ -28,6 +28,7 @@
 #include <comphelper/scopeguard.hxx>
 #include <comphelper/storagehelper.hxx>
 #include <cppcanvas/polypolygon.hxx>
+#include <osl/thread.hxx>
 
 #include <tools/debug.hxx>
 
@@ -2395,8 +2396,16 @@ void FrameSynchronization::Synchronize()
     if (mbIsActive)
     {
         // Do busy waiting for now.
-        while (maTimer.getElapsedTime() < mnNextFrameTargetTime)
-            ;
+        for(;;)
+        {
+            double remainingTime = mnNextFrameTargetTime - maTimer.getElapsedTime();
+            if(remainingTime <= 0)
+                break;
+            // Try to sleep most of it.
+            int remainingMilliseconds = remainingTime * 1000;
+            if(remainingMilliseconds > 2)
+                osl::Thread::wait(std::chrono::milliseconds(remainingMilliseconds - 2));
+        }
     }
 
     MarkCurrentFrame();


More information about the Libreoffice-commits mailing list